creating class objects inside methods
rtw at freenet.co.uk
Sun Oct 4 22:02:13 CEST 2009
Benjamin Kaplan wrote in news:mailman.838.1254682604.2807.python-
list at python.org in comp.lang.python:
>> And how do you just check a script's syntax without running it
> Because these aren't compile-time errors. Python has no compilation
Sure it does, compilation happens for every script that is executed.
And for every import, if the pre-compiled byte code can't be found it
is compiled (and the byte code saved as a .pyc or .pyo file).
Its only when a the interpreter has the complete compiled byte code
for a script or imported module that it executes anything.
Python could, if it was wanted, detect multiple syntax and other
compilation errors, but AIUI the (CPython) developers choose not
to, as it significantly simplifies (and thus speeds up) the
compilation process, which can be significant for an interpreted
For example I just ran a script with the one line:
print "hello world"
through IronPython (2.0 (18.104.22.168) on .NET 2.0.50727.3082)
I counted "1 and 2 and ... 12" before I seeing "hello world"
(Aside I think this is something that the current IronPython beta
(2.6) "fixes", but I havent tried it myself yet.)
> every statement (including def and class) is an executable
Yes but for example the execution of the statement:
def example() : pass
just assignes (binds) the compiled function to the name "example".
> statement and it gets turned into byte code at execution time. Just
> like any other language, when Python hits a runtime error, it stops.
More information about the Python-list