a question about the #prefix of sys.argv

A

Aldarion

for the little script
#egg.py
import sys
for k,v in enumerate(sys.argv):
print k,v

it ignores the part after # on linux
below is the running output on windows and linux. no clue here.
D:\python\note>egg.py #test
0 D:\python\note\egg.py
1 #test

D:\python\note>egg.py for bar #spam egg
0 D:\python\note\egg.py
1 for
2 bar
3 #spam
4 egg
ddd@bbb:~/transfer$ python2.5 egg.py #test
0 egg.py
ddd@bbb:~/transfer$ python2.5 egg.py foo bar #spam egg
0 egg.py
1 foo
2 bar
 
J

John Machin

for the little script
#egg.py
import sys
for k,v in enumerate(sys.argv):
print k,v

it ignores the part after # on linux

Perhaps "it" is the linux shell ...
 
A

Aldarion

This has nothing to do with python, it's the shell that treats the # and
everything that follows as a comment.

$ ./listargs.py alpha #beta
0 ./listargs.py
1 alpha

But you can escape it:

$ ./listargs.py alpha \#beta
0 ./listargs.py
1 alpha
2 #beta

$ ./listargs.py alpha '#beta'
0 ./listargs.py
1 alpha
2 #beta

Peter
thanks everyone for the quickly reply, i see now.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top