a question about the #prefix of sys.argv

Peter Otten __peter__ at web.de
Sun Jun 1 20:05:19 EDT 2008


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



More information about the Python-list mailing list