By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

a question about the #prefix of sys.argv

P: n/a
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
Jun 1 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Aldarion wrote:
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.
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
Jun 2 '08 #2

P: n/a
On Jun 2, 9:54 am, Aldarion <ErendisAldar...@gmail.comwrote:
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 ...
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


Jun 2 '08 #3

P: n/a
On 62, 8ʱ05, Peter Otten <__pete...@web.dewrote:
Aldarion wrote:
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.

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.
Jun 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.