470,848 Members | 1,830 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

a question about the #prefix of sys.argv

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
3 1127
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
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
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.

Similar topics

7 posts views Thread by Gui Lloyd | last post: by
1 post views Thread by Tony Johansson | last post: by
2 posts views Thread by Momo | last post: by
8 posts views Thread by mb | last post: by
9 posts views Thread by happyvalley | last post: by
4 posts views Thread by Mathias Waack | last post: by
11 posts views Thread by vicky | last post: by
4 posts views Thread by Aldarion | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.