The output of "exec dir" vs. just "dir"

Alex Farber farber at cpan.org
Tue Mar 14 23:12:19 EST 2000


Hi,

when I enter "dir" on the Python interactive prompt, 
I get "<built-in function dir>". But entering "exec 'dir'",
outputs nothing. To get the same result, I have to enter
"exec 'print dir'" (w/o double quotes). The same is true for:

   3              vs.           exec 3
 globals()        vs.         exec "globals()"

Why is it this way? Can I change it? I am asking, because 
I am simulating Python's prompt by calling Py_CompileString() + 
PyEval_EvalCode(), which is probably the same, what "exec" 
does. It works okay, but I'd like to get rid of the difference 
described above. Thank you.

Regards
Alex

PS: The complete code is at
http://www.python.org/cgi-bin/faqw.py?req=show&file=faq05.015.htp



More information about the Python-list mailing list