[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Ridiculously simple way to seperate game-object code



On 20 May 2006 at 8:51, Kris Schnee wrote:

> Doesn't Python have a "compile" function that turns a complex statement 
> into an executable code block? Something like that could be used for 
> if-branches and the like. So could a kludge like turning if/then 
> branches into GOTO statements; this could be done by some quick run-time 
> parsing, eg:
> 
It's a builtin function:

compile(source, filename, mode[, flags[, dont_inherit]]) -> code
      object

Compile the source string (a Python module, statement or expression)
into a code object that can be executed by the exec statement or 
eval().

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 argument, if present, controls which future statements 
influence the compilation of the code.

The dont_inherit argument, if non-zero, stops the compilation 
inheriting the effects of any future statements in effect in the code 
calling compile; if absent or zero these statements do influence the 
compilation, in addition to any features explicitly specified.

Lenard Lindstrom
<len-l@xxxxxxxxx>