473,287 Members | 1,580 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,287 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 1179
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.