Python 2.4 Quick Reference Card
Total Page:16
File Type:pdf, Size:1020Kb
Python 2.4 Quick Reference Card Styles : keyword function/method type replaced_expression Types basestring1 bool buffer complex dict exception file float ©2005-2007 — Laurent Pointal — License CC [by nc sa] variable literal module module_filename language_syntax Notations : frozenset int list long object set slice str tuple type unicode xrange CARD CONTENT f(…)→ return value f(…)➤ return nothing (procedure) 1 basestring is virtual superclass of str and unicode. [x] for a list of x data, (x) for a tuple of x data, may have x{n}→ Environment Variables........................1 Copying Containers...............................8 This doc uses string when unicode and str can apply. Command-line Options....................... 1 Overriding Containers Operations........ 8 n times x data. Files Extensions.................................. 1 Sequences.......................................... 8 Functions Language Keywords............................1 Lists & Tuples........................................8 ENVIRONMENT VARIABLES Constructor functions of builtin types are directly accessible in Builtins................................................1 Operations on Sequences..................... 8 1 Types.................................................... 1 Indexing................................................8 PYTHONCASEOK no case distinction in module→file mapping builtins. 1 1 Functions.............................................. 1 Operations on mutable sequences....... 8 PYTHONDEBUG = -d command-line option __import__ abs apply callable chr classmethod cmp coerce Statements......................................... 1 Overriding Sequences Operations........ 8 PYTHONHOME Modify standard Python libs prefix and exec compile delattr dir divmod enumerate eval execfile Blocks....................................................1 Mappings (dictionaries).......................8 prefix locations. Use <prefix>[:<execprefix>]. filter getattr globals hasattr hash help hex id input 2 Assignment Shortcuts...........................1 Operations on Mappings....................... 8 PYTHONINSPECT 1 = -i command-line option intern isinstance issubclass iter len locals map max min Console & Interactive Input/Output.... 2 Overriding Mapping Operations............8 PYTHONOPTIMIZE 1 = -O command-line option oct open ord pow property range raw_input reduce reload Objects, Names and Namespaces...... 2 Other Mappings.....................................9 repr reversed round setattr sorted staticmethod sum Identifiers..............................................2 Sets.....................................................9 PYTHONPATH Directories where Python search when importing modules/packages. Separator : super unichr vars zip Objects and Names, Reference Operations on Sets................................9 1 Counting............................................... 2 Other Containers Structures, (posix) or ; (windows). Under windows use Use f(*args,**kargs) in place of apply(f,args,kargs). 2 Mutable/Immutable Objects..................2 Algorithms.......................................... 9 registry HKLM\Sofware\…. Don't use intern. Namespaces......................................... 2 Array.....................................................9 PYTHONSTARTUP File to load at begining of interactive sessions. Constants, Enumerations......................2 Queue................................................... 9 STATEMENTS PYTHONUNBUFFERE 1 = -u command-line option Flow Control........................................2 Priority Queues..................................... 9 One statement per line1. Can continue on next line if an expression Condition...............................................2 Sorted List.............................................9 D Loop......................................................2 Iteration Tools.......................................9 PYTHONVERBOSE 1 = -v command-line option or a string is not finished ( ( [ { """ ''' not closed), or with a \ at Functions/methods exit.........................2 Date & Time........................................9 1 If set to non-empty value. end of line. Exceptions............................................ 2 Module time..........................................9 Char # start comments up to end of line. Iterable Protocol....................................2 Module datetime.................................10 COMMAND-LINE OPTIONS Interpretation / Execution................... 2 Module timeit......................................10 pass Null statement. Functions Definitions & Usage............ 2 Other Modules.....................................10 python [-dEhiOQStuUvVWx] [-c cmd | -m mod | file | -] [args] assert expr[,message] Assertion check expression true. Parameters / Return value....................2 Files.................................................. 10 -d Output debugging infos from parser. del name[,…] Remove name → object binding. Lambda functions................................. 2 File Objects......................................... 10 -E Ignore environment variables. print [>>obj,][expr[,…][,] Write expr to sys.stdout2. Callable Objects....................................2 Low-level Files.....................................10 -h Print help and exit. Calling Functions...................................3 Pipes................................................... 10 exec expr [in globals [, Execute expr in namespaces. -i Force interactive mode with prompt (even after script locals]] Functions Control..................................3 In-memory Files.................................. 10 execution). Decorators............................................ 3 Files Informations................................11 fct([expr[,…]], Call any callable object fct with given -O Optimize generated bytecode, remove checks. Types/Classes & Objects.....................3 Terminal Operations........................... 11 assert [ n ame = expr [,…]] arguments (see Functions Definitions -OO As -O and remove documentation strings. Class Definition.....................................3 Temporary Files.................................. 11 [,*args][,**kwargs]) & Usage - p2). Object Creation.....................................3 Path Manipulations..............................11 -Q arg Division option, arg in [old(default),warn,warnall,new]. name[,…] = expr Assignment operator3. Classes & Objects Relations..................3 Directories...........................................11 -S Don't import site.py definitions module. Attributes Manipulation.........................3 Special Files........................................ 12 -t Warn inconsistent tab/space usage (-tt exit with error). 1 Multiple statements on same line using ; separator - avoid if not Special Methods....................................3 Copying, Moving, Removing............... 12 -u Use unbuffered binary output for stdout and stderr. necessary. Descriptors protocol..............................3 Encoded Files......................................12 2 Copying Objects....................................3 Serialization........................................ 12 -U Force use of unicode literals for strings. Write to any specified object following file interface (write Introspection.........................................3 Persistence..........................................12 -v Trace imports. method). Modules and Packages........................3 Configuration Files.............................. 12 -V Print version number and exit. Write space between expressions, line-return at end of line except Source encodings..................................3 Exceptions........................................ 12 -W arg Emit warning for arg with a final ,. Special Attributes..................................3 Standard Exception Classes................12 "action:message:category:module:lineno" 3 Left part name can be container expression. If expr is a sequence Main Execution / Script Parameters.... 4 Warnings.............................................13 Operators............................................4 Exceptions Processing........................ 13 -x Skip first line of source (fort non-Unix forms of #!cmd). of multiple values, can unpack into multiple names. Can have Priority.................................................. 4 Encoding - Decoding......................... 13 -c cmd Execute cmd. multiple assignments of same value on same line : a = b = c = Arithmetic Operators............................ 4 Threads & Synchronization............... 13 -m mod Search module mod in sys.path and runs it as main script. expr. Comparison Operators..........................4 Threading Functions........................... 13 file Python script file to execute. Other statements (loops, conditions…) introduced in respective Operators as Functions.........................4 Threads...............................................13 args Command-line arguments for cmd/file, available in parts. Booleans............................................. 4 Mutual Exclusion.................................13 sys.argv[1:]. Numbers............................................. 4 Events.................................................13 Blocks Operators..............................................4 Semaphores........................................13 FILES EXTENSIONS A : between statements defines dependant statements, written on Functions.............................................. 4 Condition Variables.............................13 same line or written on following