473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1180
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 6ÔÂ2ÈÕ, ÉÏÎç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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Gui Lloyd | last post by:
I have a problem with performance in IE. The script above works quite fine when the table has a small number of elements, but, when the table has 2500 elements, when I click in the checkbox of the...
1
by: Tony Johansson | last post by:
Hello I'm trying to learn XML by reading a book. There is some text in the book that I don't understand so I try to ask you out there. My first question is does this statement mean that ...
2
by: Momo | last post by:
so if i want to see like if argv is starts with a hyphen (-), do i go like if (strncmp(argv, "-",1)==0) is this correct to check of argv begins wif a hyphen?? or is there something special for...
8
by: mb | last post by:
1) you can't declare anything outside of a class, enum, etc. Thus you can't declare globals right after the namespace declaration. I just don't understand why Microsoft decided to do away with...
9
by: happyvalley | last post by:
I just wonder how to pass arguments to this function with a char** void oldmain(int argv, char**argc) { ........ } void main(void) { int argv;
4
by: hn.ft.pris | last post by:
####################################### ........ void argParser(int, char**); int main(int argc, char** argv){ argParser(argc, argv); return 1; } void argParser(int argc, char** argv){
4
by: Mathias Waack | last post by:
We've integrated python into a legacy application. Everything works fine (of course because its python;). There's only one small problem: the application reads the commandline and consumes all...
11
by: vicky | last post by:
hi all, please tell me with example, how the *argv point to the the no of strings.
4
by: Aldarion | last post by:
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.