Matthew Bibee
2014-06-06 03:49:58 UTC
Hi
I?m a new user to wing so this might be noob kind of question. I have a script that after it is done running it needs to place a copy of itself in a log. I get very different behavior depending on if I run this script in the the shell or in the debugger. Basically the __file__ variable takes on a very different value in the shell. For example if I create a file called ?myFile.py? as:
import os
print os.path.basename(__file__)
print __file__
print __name__
print os.getcwd()
print '###################\n'
import inspect
print inspect.stack()
print '###################\n'
import sys
print sys.argv
print '###################\n'
print inspect.currentframe()
print inspect.getfile(inspect.currentframe())
Then n the debugger it will basically print out the name of the file ?myFile.py?, the full name of the path and name of the file, the top module and the name of the file that called it ??/myFile.py?.
If I run this in the shell (clicking options ?Evaluate myFile.py?) then it says the name of the file is ?_sandbox.py? and top of the frame is <winddb_compile>. It causes my actual script to bomb in a very unpleasant way as it can not actually find the file that was running. I was not expecting this when running at the shell. I was thinking my script would just run the way it normally runs at the command line and I could then try out some things on the shell prompt after it is finished. However it seems like the only way I can make this particular script work is to run in the debugger and make sure I have a dummy line of code at the end of the file with a break point set.
Is is possible to run in the python shell in wing and have it correctly acquire the true name of the __file__ variable (in this case ?myFile.py?).
Thanks
Matt
I?m a new user to wing so this might be noob kind of question. I have a script that after it is done running it needs to place a copy of itself in a log. I get very different behavior depending on if I run this script in the the shell or in the debugger. Basically the __file__ variable takes on a very different value in the shell. For example if I create a file called ?myFile.py? as:
import os
print os.path.basename(__file__)
print __file__
print __name__
print os.getcwd()
print '###################\n'
import inspect
print inspect.stack()
print '###################\n'
import sys
print sys.argv
print '###################\n'
print inspect.currentframe()
print inspect.getfile(inspect.currentframe())
Then n the debugger it will basically print out the name of the file ?myFile.py?, the full name of the path and name of the file, the top module and the name of the file that called it ??/myFile.py?.
If I run this in the shell (clicking options ?Evaluate myFile.py?) then it says the name of the file is ?_sandbox.py? and top of the frame is <winddb_compile>. It causes my actual script to bomb in a very unpleasant way as it can not actually find the file that was running. I was not expecting this when running at the shell. I was thinking my script would just run the way it normally runs at the command line and I could then try out some things on the shell prompt after it is finished. However it seems like the only way I can make this particular script work is to run in the debugger and make sure I have a dummy line of code at the end of the file with a break point set.
Is is possible to run in the python shell in wing and have it correctly acquire the true name of the __file__ variable (in this case ?myFile.py?).
Thanks
Matt