PDA

View Full Version : python sys.argv problem


s2d4
January 22nd, 2008, 12:39 AM
Hi,

I am having problem displaying the input argument. Since it isn't used for opening files (I just need an integer input), the following wont work, I am a noob after all. Any suggestions?

number = sys.argv[2]
print number

Wybiral
January 22nd, 2008, 12:43 AM
Step #1 towards learning to program: If something doesn't work, see if the compiler/interpreter generates an error, if so, read it. If you don't understand it, post it here. :)

LaRoza
January 22nd, 2008, 12:45 AM
Hi,

I am having problem displaying the input argument. Since it isn't used for opening files (I just need an integer input), the following wont work, I am a noob after all. Any suggestions?

number = sys.argv[2]
print number


import sys

for i in sys.argv:
print i


The first member of argv (argv[0]) will be the program name, the second (argv[1]) will be the first command line argument.

s2d4
January 22nd, 2008, 01:07 AM
Cheers buddy, I was able to extract the argument that I want to display after some modification.


import sys

for i in sys.argv:
print i


The first member of argv (argv[0]) will be the program name, the second (argv[1]) will be the first command line argument.