How to eval a file

Bengt Richter bokr at oz.net
Sun Feb 23 02:23:28 EST 2003


On 23 Feb 2003 00:32:45 +0100, d95-bli at nada.kth.se (=?iso-8859-1?q?Bj=F6rn?= Lindberg) wrote:
[...]
>
>I tried using execfile() without success. However, I thought that the
If you'd posted a minimal example of what you did "without success,"
with copy/paste of the screen interaction and/or test run, I'd bet you
would know by now how to make it work ;-)

>local variables would just magically spring into existance. As others
>have shown in other posts, I'll have to give an environment argument
>to execfile. I thought it would work more like when sourcing a file of
>commands in a shell script.

 Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> help(execfile)
 Help on built-in function execfile:

 execfile(...)
     execfile(filename[, globals[, locals]])

     Read and execute a Python script from a file.
     The globals and locals are dictionaries, defaulting to the current
     globals and locals.  If only globals is given, locals defaults to it.

>
>> Also, remember that you should be careful when using exec and its
>> variants.  A person could put malicious code into the conffile, and
>> you should be aware of that.
>
>Yes. This is a web application, and the person setting up the service
>is supposed to be the same as the one who writes the configure
>file. But you are right, I will take it into consideration.
Worth requoting.

Regards,
Bengt Richter




More information about the Python-list mailing list