Bug? (ActivePython)

Bengt Richter bokr at oz.net
Thu Jan 2 04:43:16 EST 2003


On Wed, 01 Jan 2003 03:39:30 +0000, Tetsuo <member at dbforums.com> wrote:

>
>Originally posted by Jp Calderone 
>>
>>   "404 error?  Is this in a CGI?"
>>
>> Alright... IOError.
>>
>>   "The locals dictionary the code is executed in is different.
>>   Without
>> knowing what's in pystone.py, saying more is difficult."
>>
>> That statement is clear as mud to me... (So is the phrase "locals
>> dictionary,"
>> may be I should look it up...) Pystone is a standard module... You
>> have it in lib\test.
>
I suspect you might have two problems:

1) You may have run your two examples in different contexts, one of
   which had pystone.py in the current working directory and the other not.
   To see where the program is looking for 'pystone.py', put the following
   line before the execfile:

   import os; print os.getcwd()

   One solution is to specify the full path to pystone.py in the first arg passed
   to execfile. This alone will not make it work though:

2) execfile uses default local and global directories unless you specify
   what they should be. Inside a function, you will need to specify them,
   or else the global results of execfile will go to the "wrong" place, and
   the global reference to the pystones function in main will get a NameError,
   which is what is giving you your "bug".

   Try writing your execfile statement in the function as

       execfile(r"d:\python22\lib\test\pystone.py", locals())  # (your full path may vary)

   Or if you move a copy of pystone.py into the directory that gets printed from
   import os; print os.getcwd(), then you can just write

       execfile("pystone.py", locals())  # depends on pystone.py's being in current working dir.

Regards,
Bengt Richter




More information about the Python-list mailing list