469,306 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Passing Arguments

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
>>python using_sys.py test1 test2 test3
I get the following error:
SyntaxError: invalid syntax

How can I fix this?

Sep 29 '06 #1
1 5093
It works fine when I 'Run Module'...but when I type in interactive mode
in the Python Shell
>>>python using_sys.py test1 test2 test3

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:~/tmppython -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.


Sep 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Pavils Jurjans | last post: by
3 posts views Thread by domeceo | last post: by
7 posts views Thread by Harolds | last post: by
5 posts views Thread by Michael | last post: by
3 posts views Thread by Mantorok | last post: by
4 posts views Thread by Justine | last post: by
2 posts views Thread by william.w.oneill | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.