a question about the #prefix of sys.argv

Aldarion ErendisAldarion at gmail.com
Sun Jun 1 20:50:33 EDT 2008


On 6月2日, 上午8时05分, Peter Otten <__pete... at web.de> wrote:
> 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.



More information about the Python-list mailing list