Commit e685f943 authored by Raymond Hettinger's avatar Raymond Hettinger

Part 3 of Py2.3 update

parent e4c40da0
......@@ -208,7 +208,7 @@ Highest Operator Comment
calls
+x, -x, ~x Unary operators
x**y Power
x*y x/y x%y mult, division, modulo
x*y x/y x%y x//y mult, division, modulo, floor division
x+y x-y addition, substraction
x<<y x>>y Bit shifting
x&y Bitwise and
......@@ -332,13 +332,15 @@ OverflowError
numeric bounds exceeded
ZeroDivisionError
raised when zero second argument of div or modulo op
FloatingPointError
raised when a floating point operation fails
Operations on all sequence types (lists, tuples, strings)
Operations on all sequence types
Operation Result Notes
x in s 1 if an item of s is equal to x, else 0
x not in s 0 if an item of s is equal to x, else 1
x in s True if an item of s is equal to x, else False
x not in s False if an item of s is equal to x, else True
for x in s: loops over the sequence
s + t the concatenation of s and t
s * n, n*s n copies of s concatenated
......@@ -404,7 +406,7 @@ del d[k] remove d[k] from d (1)
d.clear() remove all items from d
d.copy() a shallow copy of d
d.get(k,defaultval) the item of d with key k (4)
d.has_key(k) 1 if d has key k, else 0
d.has_key(k) True if d has key k, else False
d.items() a copy of d's list of (key, item) pairs (2)
d.iteritems() an iterator over (key, value) pairs (7)
d.iterkeys() an iterator over the keys of d (7)
......@@ -599,7 +601,7 @@ Operators on file objects
f.close() Close file f.
f.fileno() Get fileno (fd) for file f.
f.flush() Flush file f's internal buffer.
f.isatty() 1 if file f is connected to a tty-like dev, else 0.
f.isatty() True if file f is connected to a tty-like dev, else False.
f.read([size]) Read at most size bytes from file f and return as a string
object. If size omitted, read to EOF.
f.readline() Read one entire line from file f.
......@@ -619,7 +621,9 @@ File Exceptions
End-of-file hit when reading (may be raised many times, e.g. if f is a
tty).
IOError
Other I/O-related I/O operation failure
Other I/O-related I/O operation failure.
OSError
OS system call failed.
Advanced Types
......@@ -717,6 +721,10 @@ File Exceptions
continue -- immediately does next iteration of "for" or "while" loop
return [result] -- Exits from function (or method) and returns result (use a tuple to
return more than one value). If no result given, then returns None.
yield result -- Freezes the execution frame of a generator and returns the result
to the iterator's .next() method. Upon the next call to next(),
resumes execution at the frozen point with all of the local variables
still intact.
Exception Statements
......@@ -919,8 +927,12 @@ fromlist]]])
abs(x) Return the absolute value of number x.
apply(f, args[, Calls func/method f with arguments args and optional
keywords]) keywords.
callable(x) Returns 1 if x callable, else 0.
bool(x) Returns True when the argument x is true and False otherwise.
buffer(obj) Creates a buffer reference to an object.
callable(x) Returns True if x callable, else False.
chr(i) Returns one-character string whose ASCII code isinteger i
classmethod(f) Converts a function f, into a method with the class as the
first argument. Useful for creating alternative constructors.
cmp(x,y) Returns negative, 0, positive if x <, ==, > to y
coerce(x,y) Returns a tuple of the two numeric arguments converted to a
common type.
......@@ -934,15 +946,18 @@ complex(real[, Builds a complex object (can also be done using J or j
image]) suffix,e.g. 1+3J)
delattr(obj, name) deletes attribute named name of object obj <=> del obj.name
If no args, returns the list of names in current
dict([items]) Create a new dictionary from the specified item list.
dir([object]) localsymbol table. With a module, class or class
instanceobject as arg, returns list of names in its attr.
dict.
divmod(a,b) Returns tuple of (a/b, a%b)
enumerate(seq) Return a iterator giving: (0, seq[0]), (1, seq[1]), ...
eval(s[, globals[, Eval string s in (optional) globals, locals contexts.s must
locals]]) have no NUL's or newlines. s can also be acode object.
Example: x = 1; incr_x = eval('x + 1')
execfile(file[, Executes a file without creating a new module, unlike
globals[, locals]]) import.
file() Synonym for open().
filter(function, Constructs a list from those elements of sequence for which
sequence) function returns true. function takes one parameter.
float(x) Converts a number or a string to floating point.
......@@ -953,6 +968,7 @@ globals() Returns a dictionary containing current global variables.
hasattr(object, Returns true if object has attr called name.
name)
hash(object) Returns the hash value of the object (if it has one)
help(f) Display documentation on object f.
hex(x) Converts a number x to a hexadecimal string.
id(object) Returns a unique 'identity' integer for an object.
input([prompt]) Prints prompt if given. Reads input and evaluates it.
......@@ -966,6 +982,7 @@ class) (A,B) then isinstance(x,A) => isinstance(x,B)
issubclass(class1, returns true if class1 is derived from class2
class2)
Returns the length (the number of items) of an object
iter(collection) Returns an iterator over the collection.
len(obj) (sequence, dictionary, or instance of class implementing
__len__).
list(sequence) Converts sequence into a list. If already a list,returns a
......@@ -987,7 +1004,12 @@ implementation 1 for line-buffered, negative forsys-default, all else, of
dependent]]) (about) given size.
ord(c) Returns integer ASCII value of c (a string of len 1). Works
with Unicode char.
object() Create a base type. Used as a superclass for new-style objects.
open(name Open a file.
[, mode
[, buffering]])
pow(x, y [, z]) Returns x to power y [modulo z]. See also ** operator.
property() Created a property with access controlled by functions.
range(start [,end Returns list of ints from >= start and < end.With 1 arg,
[, step]]) list from 0..arg-1With 2 args, list from start..end-1With 3
args, list from start up to end by step
......@@ -1012,8 +1034,13 @@ name, value) 3) <=> o.foobar = 3Creates attribute if it doesn't exist!
slice([start,] stop Returns a slice object representing a range, with R/
[, step]) Oattributes: start, stop, step.
Returns a string containing a nicely
staticmethod() Convert a function to method with no self or class
argument. Useful for methods associated with a class that
do not need access to an object's internal state.
str(object) printablerepresentation of an object. Class overridable
(__str__).See also repr().
super(type) Create an unbound super object. Used to call cooperative
superclass methods.
tuple(sequence) Creates a tuple with same elements as sequence. If already
a tuple, return itself (not a copy).
Returns a type object [see module types] representing
......@@ -1045,6 +1072,8 @@ Exception>
Root class for all exceptions
SystemExit
On 'sys.exit()'
StopIteration
Signal the end from iterator.next()
StandardError
Base class for all built-in exceptions; derived from Exception
root class.
......@@ -1099,6 +1128,14 @@ Exception>
On passing inappropriate type to built-in op or func
ValueError
On arg error not covered by TypeError or more precise
Warning
UserWarning
DeprecationWarning
PendingDeprecationWarning
SyntaxWarning
OverflowWarning
RuntimeWarning
FutureWarning
......@@ -1122,7 +1159,7 @@ Special methods for any class
__cmp__(s, o) Compares s to o and returns <0, 0, or >0.
Implements >, <, == etc...
__hash__(s) Compute a 32 bit hash code; hash() and dictionary ops
__nonzero__(s) Returns 0 or 1 for truth value testing
__nonzero__(s) Returns False or True for truth value testing
__getattr__(s, name) called when attr lookup doesn't find <name>
__setattr__(s, name, val) called when setting an attr
(inside, don't use "self.name = value"
......@@ -1188,19 +1225,16 @@ Operators
Special informative state attributes for some types:
Lists & Dictionaries:
__methods__ (list, R/O): list of method names of the object
Modules:
__doc__ (string/None, R/O): doc string (<=> __dict__['__doc__'])
__name__(string, R/O): module name (also in __dict__['__name__'])
__dict__ (dict, R/O): module's name space
__file__(string/undefined, R/O): pathname of .pyc, .pyo or .pyd (undef for
modules statically linked to the interpreter)
__path__(string/undefined, R/O): fully qualified package name when applies.
Classes: [in bold: writable since 1.5.2]
__doc__ (string/None, R/W): doc string (<=> __dict__['__doc__'])
__module__ is the module name in which the class was defined
__name__(string, R/W): class name (also in __dict__['__name__'])
__bases__ (tuple, R/W): parent classes
__dict__ (dict, R/W): attributes (class name space)
......@@ -1208,6 +1242,7 @@ Special informative state attributes for some types:
Instances:
__class__ (class, R/W): instance's class
__dict__ (dict, R/W): attributes
User-defined functions: [bold: writable since 1.5.2]
__doc__ (string/None, R/W): doc string
__name__(string, R/O): function name
......@@ -1216,6 +1251,11 @@ Special informative state attributes for some types:
func_defaults (tuple/None, R/W): default args values if any
func_code (code, R/W): code object representing the compiled function body
func_globals (dict, R/O): ref to dictionary of func global variables
func_dict (dict, R/W): same as __dict__ contains the namespace supporting
arbitrary function attributes
func_closure (R/O): None or a tuple of cells that contain bindings
for the function's free variables.
User-defined Methods:
__doc__ (string/None, R/O): doc string
......@@ -1223,16 +1263,20 @@ Special informative state attributes for some types:
im_class (class, R/O): class defining the method (may be a base class)
im_self (instance/None, R/O): target instance object (None if unbound)
im_func (function, R/O): function object
Built-in Functions & methods:
__doc__ (string/None, R/O): doc string
__name__ (string, R/O): function name
__self__ : [methods only] target object
__members__ = list of attr names: ['__doc__','__name__','__self__'])
Codes:
co_name (string, R/O): function name
co_argcount (int, R/0): number of positional args
co_nlocals (int, R/O): number of local vars (including args)
co_varnames (tuple, R/O): names of local vars (starting with args)
co_cellvars (tuple, R/O)) the names of local variables referenced by
nested functions
co_freevars (tuple, R/O)) names of free variables
co_code (string, R/O): sequence of bytecode instructions
co_consts (tuple, R/O): litterals used by the bytecode, 1st one is
fct doc (or None)
......@@ -1241,7 +1285,6 @@ Special informative state attributes for some types:
co_firstlineno (int, R/O): first line number of the function
co_lnotab (string, R/O): string encoding bytecode offsets to line numbers.
co_stacksize (int, R/O): required stack size (including local vars)
co_firstlineno (int, R/O): first line number of the function
co_flags (int, R/O): flags for the interpreter
bit 2 set if fct uses "*arg" syntax
bit 3 set if fct uses '**keywords' syntax
......@@ -1274,8 +1317,6 @@ Special informative state attributes for some types:
Complex numbers:
real (float, R/O): real part
imag (float, R/O): imaginary part
XRanges:
tolist (Built-in method, R/O): ?
Important Modules
......@@ -1316,18 +1357,18 @@ version_info tuple containing Python version info - (major, minor,
Function Result
exit(n) Exits with status n. Raises SystemExit exception.(Hence can
be caught and ignored by program)
getrefcount(object Returns the reference count of the object. Generally 1
) higherthan you might expect, because of object arg temp
getrefcount(object Returns the reference count of the object. Generally one
) higher than you might expect, because of object arg temp
reference.
setcheckinterval( Sets the interpreter's thread switching interval (in number
interval) ofvirtualcode instructions, default:10).
interval) of virtual code instructions, default:10).
settrace(func) Sets a trace function: called before each line ofcode is
exited.
setprofile(func) Sets a profile function for performance profiling.
Info on exception currently being handled; this is atuple
(exc_type, exc_value, exc_traceback).Warning: assigning the
exc_info() traceback return value to a loca variable in a
functionhandling an exception will cause a circular
function handling an exception will cause a circular
reference.
setdefaultencoding Change default Unicode encoding - defaults to 7-bit ASCII.
(encoding)
......@@ -1754,16 +1795,18 @@ atan2(x, y)
ceil(x)
cos(x)
cosh(x)
degrees(x)
exp(x)
fabs(x)
floor(x)
fmod(x, y)
frexp(x) -- Unlike C: (float, int) = frexp(float)
ldexp(x, y)
log(x)
log(x [,base])
log10(x)
modf(x) -- Unlike C: (float, float) = modf(float)
pow(x, y)
radians(x)
sin(x)
sinh(x)
sqrt(x)
......@@ -1981,8 +2024,6 @@ zipfile Read & write PK zipped files.
(following list not revised)
* Built-ins *
sys Interpreter state vars and functions
......@@ -1990,7 +2031,7 @@ zipfile Read & write PK zipped files.
__main__ Scope of the interpreters main program, script or stdin
array Obj efficiently representing arrays of basic values
math Math functions of C standard
time Time-related functions
time Time-related functions (also the newer datetime module)
regex Regular expression matching operations
marshal Read and write some python values in binary format
struct Convert between python values and C structs
......@@ -2001,7 +2042,7 @@ zipfile Read & write PK zipped files.
os A more portable interface to OS dependent functionality
re Functions useful for working with regular expressions
string Useful string and characters functions and exceptions
whrandom Wichmann-Hill pseudo-random number generator
random Mersenne Twister pseudo-random number generator
thread Low-level primitives for working with process threads
threading idem, new recommanded interface.
......@@ -2031,6 +2072,7 @@ zipfile Read & write PK zipped files.
md5 Interface to RSA's MD5 message digest algorithm
mpz Interface to int part of GNU multiple precision library
rotor Implementation of a rotor-based encryption algorithm
HMAC Keyed-Hashing for Message Authentication -- RFC 2104.
* Stdwin * Standard Window System
......@@ -2060,8 +2102,6 @@ Workspace exploration and idiom hints
dir(<module>) list functions, variables in <module>
dir() get object keys, defaults to local name space
X.__methods__ list of methods supported by X (if any)
X.__members__ List of X's data attributes
if __name__ == '__main__': main() invoke main if running as script
map(None, lst1, lst2, ...) merge lists
b = a[:] create copy of seq structure
......@@ -2107,6 +2147,8 @@ C-c C-c sends the entire buffer to the Python interpreter
C-c | sends the current region
C-c ! starts a Python interpreter window; this will be used by
subsequent C-c C-c or C-c | commands
C-c C-w runs PyChecker
VARIABLES
py-indent-offset indentation increment
py-block-comment-prefix comment string used by py-comment-region
......@@ -2169,6 +2211,8 @@ r, return
can be printed or manipulated from debugger)
c, continue
continue until next breakpoint
j, jump lineno
Set the next line that will be executed
a, args
print args to current function
rv, retval
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment