Fuzzyman a écrit :
The following two passages from the python documentation *appear* to
contradict each other. Equally possible (or more likely !) is that I
misunderstand it :

eval :
This function can also be used to execute arbitrary code objects (such
as those created by compile()). In this case pass a code object instead
of a string. The code object must have been compiled passing 'eval' as
the kind argument.


compile: The kind argument specifies what kind of code must be compiled; it can be 'exec' if string consists of a sequence of statements, 'eval' if it consists of a single expression, or 'single' if it consists of a single interactive statement (in the latter case, expression statements that evaluate to something else than None will be printed).

The docs for compile say that if you are creating a code object from a
sequence of statements you must use the kind argument 'exec'. Eval says
that if you are using the eval function you must use 'eval' as your
kind argument.

In practise I have found that using the eval function with code objects
compiled with 'exec' as the kind argument works fine. Is this a 'bug'
in the docs ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml


IMO, it's just logical the code sent to "eval" was compiled with "eval" as the kind argument. But don't forget the documentation is kind of "abstract" and that CPython is _just_ an implementation (ok, it's the reference implementation) of python. You'd better follow the doc if you want your code to work on other Python implementation (ie. JPython, ...).


Pierre
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to