How to eval a file

Alex Martelli aleax at aleax.it
Sun Feb 23 12:23:06 EST 2003


Björn Lindberg wrote:
   ...
> Please see my other post of an example where execfile() doesn't import
> the variables into the global namespace. Either the behaviour doesn't
> conform to the documentation, or (much more likely) I don't understand
> Python namespaces well enough.

Please see my detailed response to that post, including the excerpt
from the online documentation that mentions this behavior.  You're
quite right that the condensed information in the docstring doesn't
contain all of this, and neither did my somewhat hasty previous
answer (sorry!).


>> This is a reasonable compromise.  But make sure you use execfile
>> WITH an explicit namespace anyway -- even just to debug &c -- you'll
>> be glad you did.
> 
> I found the shlex module which made it really easy to parse my
> configuration file, so I'm doing that now.

OK, if you can stay away from eval/exec/execfile altogether, you'll no
doubt be even gladder;-).


Alex





More information about the Python-list mailing list