ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH

Reference
ActivePython 2.5
Python Documentation
Library Reference
31. Python compiler package
31.1 The basic interface
31.2 Limitations
31.3 Python Abstract Syntax
31.4 Using Visitors to Walk ASTs
31.5 Bytecode Generation

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 31. Python compiler package
ActivePython 2.5 documentation

31.1 The basic interface

The top-level of the package defines four functions. If you import compiler, you will get these functions and a collection of modules contained in the package.

parse( buf)
Returns an abstract syntax tree for the Python source code in buf. The function raises SyntaxError if there is an error in the source code. The return value is a compiler.ast.Module instance that contains the tree.

parseFile( path)
Return an abstract syntax tree for the Python source code in the file specified by path. It is equivalent to parse(open(path).read()).

walk( ast, visitor[, verbose])
Do a pre-order walk over the abstract syntax tree ast. Call the appropriate method on the visitor instance for each node encountered.

compile( source, filename, mode, flags=None, dont_inherit=None)
Compile the string source, a Python module, statement or expression, into a code object that can be executed by the exec statement or eval(). This function is a replacement for the built-in compile() function.

The filename will be used for run-time error messages.

The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression.

The flags and dont_inherit arguments affect future-related statements, but are not supported yet.

compileFile( source)
Compiles the file source and generates a .pyc file.

The compiler package contains the following modules: ast, consts, future, misc, pyassem, pycodegen, symbols, transformer, and visitor.

See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved