Passing Arguments

T

theemails

New to Python ... this should be an easy question to answer.

INPUT

import sys

print 'The command line arguments are:'
for i in sys.argv:
print i

print '\nThe PYTHONPATH is', sys.path

OUTPUT
The command line arguments are:
C:\Python25\using_sys.py

The PYTHONPATH is ['C:\\Python25\\Lib\\idlelib',
'C:\\Python25\\python25.zip', 'C:\\Python25\\DLLs',
'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25',
'C:\\Python25\\lib\\site-packages']

It works fine when I 'Run Module'...but when I type in interactive mode
in the Python Shell
I get the following error:
SyntaxError: invalid syntax

How can I fix this?
 
T

Tim Chase

It works fine when I 'Run Module'...but when I type in interactive mode
in the Python Shell

I get the following error:
SyntaxError: invalid syntax


By using proper syntax... :*)

To pass parameters, you do it when *starting* python[*]. Thus,
you'd use something like

c:\test\> python -i using_sys.py test1 test2 test3

or

tim@oblique:~/tmp> python -i using_sys.py test1 test2 test3

from your *system* command-prompt/shell (not the python shell)
which will (with the "-i" parameter) leave you in the *python*
command interpreter/shell.

-tkc


[*] yes, you can write to the sys.argv to make them what you
want for testing purposes, but that's intentionally and
purposefully prevaricating about the meaning of "argv". Best
left for when it's what you really mean to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top