TP <[EMAIL PROTECTED]> writes: > Hello, > > I have a script that uses the "optparse" package to parse the command line. > For example: > > $ script.py --help > # displays help about script.py > > Is this possible to call such a script with execfile('') once in the Python > interactive shell? > >>>> execfile( 'script.py' ) > > I get errors because there is no argv dictionary when used with execfile. > > How to solve this problem, so that I am able to use script.py in command > line as well as with execfile?
Have you tried setting sys.argv manually? e.g. >>> import sys >>> sys.argv = ['--help'] >>> execfile('script.py') But I have to say I have never felt the need to use execfile() this way. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list