Since the beginning of Python2.6 , a new function of format string str has been added. format ()GrammarIt replaces% with {} and:.Map sampleby locationIn [1]: ‘{0},{1}‘.format(‘kzc‘,18) Out[1]: ‘kzc,18‘ In [2]: ‘{},{}‘.format(‘kzc‘,18) Out[2]: ‘kzc,18‘ In [3]: ‘{1},{0},{1}‘.format
the file (HTML, TPL, etc.) must be GBK, and see the following diagram will be clearer:
DB (GBK) => PHP (encoding format is not limited but if there are Chinese characters in the code file, the file will be GBK encoded or converted to GBK when the Chinese character is exported) => header (GBK) => html, TPL (GBK)
Or there is a way to only when the library in the code in the UTF8 into the GBK, in general utf8 or more popular point, less problem
DB (G
Summary of common Python string formatting methods [percent and format methods] And pythonformat
This document describes common methods for formatting strings in Python. We will share this with you for your reference. The details are as follows:
Method 1: percent sign (%). The printf of class C must be of different types.
1. Anonymous tuple. (We recommend that
We can use the time module in Python Mktime method will be converted to UNIX timestamp, mktime function can only accept the corresponding time Ganso sequence. Before you do this, you need to convert the input time to a tuple sequence:If the input time is in the specified format, you can use the Strptime () function to parse a time string into a time tuple based on the specified format.Time. Strptime(string
Excerpt from: http://blog.csdn.net/forandever/article/details/5711319A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file@for ever 2010-07-03Function:Gets the file name and file modification time for the specified directory under certain rules, and saves it to the specified fileThe script is as follows:#!/usr/bin/env
Linux under many configuration files in addition to the INI format can be used in Python configparser module, you can write a simple code of their own only "key=value" such a conf configuration file to parse into a dictionary, The key corresponding to key can be easily obtained by using the dictionary keys. The Python implementation method is relatively simple, a
Recently research on CSS, not to go online analysis of other people's Web pages, but many of the Web site's CSS files are either written in one line, or a line is not, it seems extremely painful, so write a script to convert to a more readable format. Here's the script:
Import string, sys
import Re, Stringio
tab=4
def format (ss):
f = open (ss, "R")
data = F.read ()
F . Close ()
Dlen
Python outputs the instance code in json format, pythonjson
There is a requirement that json format data should be displayed in the standard output of python. If the indent display shows the data, it will work very well. Here, there will be a lot of operations to use the json package.
Import json date = {u'version': [{
Scenario One: If it is 32/64 bit win XP or 32/64 bit Win 7 (this article is written according to the program.) )Installing Python-2.7.3.msiInstalling Pywin32-218.win32-py2.7.exeUnzip Pyinstaller-2.0.zip (any directory is OK)Copy Upx.exeScenario Two: If it is 64-bit win XP or 64-bit win 7Installing Python-2.7.3.amd64.msiInstalling Pywin32-218.win-amd64-py2.7.exeUnzip Pyinstaller-2.0.zip (any directory is OK
This example describes how Python uses xlrd to read Excel format files. Share to everyone for your reference. Specifically as follows:
Using XLRD can easily read the contents of Excel file, and this is a cross-platform library, can be used in Windows,linux/unix, and other platforms, the code is as follows:
Import xlrd
fname = "Sample.xls"
bk = Xlrd.open_workbook (fname)
Shxrange = Range (bk.nsheets)
t
percentages (6 digits after the decimal point by default)
Common formatting:TPL ="I am {}, age {}, {}". Format ("Seven", 18,'Alex') TPL="I am {}, age {}, {}". Format (*["Seven", 18,'Alex']) TPL="I am {0}, age {1}, really {0}". Format ("Seven", 18) TPL="I am {0}, age {1}, really {0}". Format (*["Seven", 18]) TPL="
; s . __func__ () ' This guy is Jihite, was 4 old 'by subscript>>> ' {0[0]} is {0[1]} years old! '. Format ([' Jihite ', 4]) ' Jihite is 4 years old! ' >>> ' {0} is {1} years old! '. Format (' Jihite ', 4) ' Jihite is 4 years old! 'is actually through the locationFormat qualifierThrough {}: symbolFill and align^>>> ' {: >10} '. Format (' jihite ') ' jihite ' >
Several python files have recently been modified and found to be executed only with Python file on Linux, directly./file the error "No such file or directory", and the script starts with "#!/usr/bin/env python", Should be straightforward to execute. In general, this error is caused by no permissions. However, this script has execute permission. Google found that
import csvfrom matplotlib import pyplot as pltfrom datetime import Datetimefilename = ' sitka_weather_07-2014.csv ' with open (fileName) as F:reader = Csv.reader (f) header_row = Next (rea Der) # Print (header_row) # for index, Column_header in Enumerate (header_row): # When you need both index and value values, you can use enumerate # # Print (index, column_header) dates,hights = [], [] for row in reader:current_date = Datetime.strpt IME (row[0], '%y-%m-%d ') dates.append (current_date) high
This article mainly introduces the use of Python to convert images into Excel documents related content, wrote a small piece of Python code, the image into Excel, purely entertainment, The following article mainly introduces you to the use of Python to convert the image into Excel document format of the relevant inform
The example of this article summarizes the Python format string method, shared for everyone to reference. The specific analysis is as follows:
The Python string formatting method is expressed as an example:
* Define WidthThe Python code is as follows:
>>> '%*s ' (5, ' some ')
' some '
-Left alignmentThe
In [7]: p=[' kzc ', +] in
[8]: ' {0[0]},{0[1]} '. Format (p)
out[8]: ' kzc,18 '
With these convenient "mapping" way, we have a lazy weapon. The basic Python knowledge tells us that lists and tuple can be "broken" into ordinary parameters to the function, and dict can be broken into the keyword parameters to the function (through and *). So you can easily pass a list/tuple/dict to the
During the internship, a brother of the server asked me to help tidy up the log data of the server, and finally I used Python to extract the data and export it in Excel format. Below is my python implementation of the source code, you can automatically traverse a file directory of all text files, and the total data exported to Excel file, exported to Excel
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.