python: built-in method cont1.
时间:2008-09-27 来源:chunliny
13. list( | [sequence]) |
>>> list((1,2,4,5)) |
dict( | [mapping-or-sequence]) |
If keyword arguments are given, the keywords themselves with their associated values are added as items to the dictionary. If a key is specified both in the positional argument and as a keyword argument, the value associated with the keyword is retained in the dictionary.
For example, these all return a dictionary equal to {"one": 2, "two": 3}:
>>> dict({'one': 2, 'two': 3}) |
New in version 2.2. Changed in version 2.3: Support for building a dictionary from keyword arguments added.
tuple( | [sequence]) |
>>> tuple("abc") |
set( | [iterable]) |
>>> set('ycl') |
14. file( | filename[, mode[, bufsize]]) |
Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files (else it is ignored). If the file cannot be opened, IOError is raised.
In addition to the standard fopen() values mode may be 'U' or 'rU'. If Python is built with universal newline support (the default) the file is opened as a text file, but lines may be terminated by any of '\n', the Unix end-of-line convention, '\r', the Macintosh convention or '\r\n', the Windows convention. All of these external representations are seen as '\n' by the Python program. If Python is built without universal newline supportmode 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types seen.
If mode is omitted, it defaults to 'r'. When opening a binary file, you should append 'b' to the mode value for improved portability. (It's useful even on systems which don't treat binary and text files differently, where it serves as documentation.) The optional bufsize argument specifies the file's desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative bufsize means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used.2.3
The file() constructor is new in Python 2.2. The previous spelling, open(), is retained for compatibility, and is an alias for file().
open( | filename[, mode[, bufsize]]) |
15.
globals( | ) |
locals( | ) |
16.
getattr( | object, name[, default]) |
setattr( | object, name, value) |
getattr(a, x) |
17. sum( | sequence[, start]) |
| |
repr( | object) |
str( | [object]) |
unicode( | [object[, encoding [, errors]]]) |
If encoding and/or errors are given, unicode() will decode the object which can either be an 8-bit string or a character buffer using the codec for encoding. The encoding parameter is a string giving the name of an encoding; if the encoding is not known, LookupError is raised. Error handling is done according to errors; this specifies the treatment of characters which are invalid in the input encoding. If errors is 'strict' (the default), a ValueError is raised on errors, while a value of 'ignore' causes errors to be silently ignored, and a value of 'replace' causes the official Unicode replacement character, U+FFFD, to be used to replace input characters which cannot be decoded. See also the codecs module.
If no optional parameters are given, unicode() will mimic the behaviour of str() except that it returns Unicode strings instead of 8-bit strings. More precisely, if object is a Unicode string or subclass it will return that Unicode string without any additional decoding applied.
For objects which provide a __unicode__() method, it will call this method without arguments to create a Unicode string. For all other objects, the 8-bit string version or representation is requested and then converted to a Unicode string using the codec for the default encoding in 'strict' mode.
New in version 2.0. Changed in version 2.2: Support for __unicode__() added.
a + 'yang' |
19. round( | x[, n]) |
相关阅读 更多 +
排行榜 更多 +
|