473,671 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

len(sys.argv) in (3,4)

Hello

I wrote a simple module, which is also supposed to be used as standalone
program
after considering how to avoid multiple if's I came up with this idea

if __name__ == "__main__":
if len(sys.argv) not in (3,4):
print "usage: prog arg1 argv2 [-x]"
# etc ...

while develeoping I had my interpeter running and reloaded module
now since I am ready, I wanted to run it from cmd windows shell
but it always prints "usage ..."
I added print len(sys.arg) and it prints 1 though I am provinding more
than 1 value
C:\pool\vhd2h\p ython>vhd2h.py vhd.vhd vhd.h -o
1
usage: vhd2h.py vhdlFile hFile [-o]

Someone got an idea what may be wrong?

--
Daniel
Aug 11 '05 #1
9 3654
Daniel Schüle wrote:
Hello

I wrote a simple module, which is also supposed to be used as standalone
program
after considering how to avoid multiple if's I came up with this idea

if __name__ == "__main__":
if len(sys.argv) not in (3,4):
print "usage: prog arg1 argv2 [-x]"
# etc ...

while develeoping I had my interpeter running and reloaded module
now since I am ready, I wanted to run it from cmd windows shell
but it always prints "usage ..."
I added print len(sys.arg) and it prints 1 though I am provinding more
than 1 value
C:\pool\vhd2h\p ython>vhd2h.py vhd.vhd vhd.h -o
1
usage: vhd2h.py vhdlFile hFile [-o]

Someone got an idea what may be wrong?
Nope. But since you're running this on a very peculiar OS, I just can
guess that this very peculiar OS consider all args to be one same string...

Try this:
if __name__ == "__main__":
for num, arg in enumerate(sys.a rgv):
print "arg %d is %s" % (num, arg)

This should art least give you some hints...

BTW, isn't the DOS syntax for command line args something like : myprog /arg1 /arg2


???
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Aug 11 '05 #2
Daniel Schüle wrote:
if __name__ == "__main__":
if len(sys.argv) not in (3,4):
print "usage: prog arg1 argv2 [-x]"
# etc ...

while develeoping I had my interpeter running and reloaded module
now since I am ready, I wanted to run it from cmd windows shell
but it always prints "usage ..."
I added print len(sys.arg) and it prints 1 though I am provinding more
than 1 value


Add

import sys
print sys.argv

at the top of the script before any other import.
Maybe one of the modules you're importing messes with sys.argv

Daniel
Aug 11 '05 #3
I just tried the same code at home and it worked fine
it has to do with windows .. some settings or whatever
(python 2.4.1 installed on both)

maybe someone have experienced the same problem
and had more luck in solving the puzzle
Aug 11 '05 #4
bruno modulix wrote:
Daniel Schüle wrote:
Hello

I wrote a simple module, which is also supposed to be used as standalone
program
after considering how to avoid multiple if's I came up with this idea

if __name__ == "__main__":
if len(sys.argv) not in (3,4):
print "usage: prog arg1 argv2 [-x]"
# etc ...

while develeoping I had my interpeter running and reloaded module
now since I am ready, I wanted to run it from cmd windows shell
but it always prints "usage ..."
I added print len(sys.arg) and it prints 1 though I am provinding more
than 1 value
C:\pool\vhd2h \python>vhd2h.p y vhd.vhd vhd.h -o
1
usage: vhd2h.py vhdlFile hFile [-o]

Someone got an idea what may be wrong?

Nope. But since you're running this on a very peculiar OS, I just can
guess that this very peculiar OS consider all args to be one same string...


NOT SO:

C:\junk>python -i - foo /bar -zot
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright" , "credits" or "license" for more information.
import sys
sys.argv

['-', 'foo', '/bar', '-zot']

NO REASON TO GUESS SO:

For *any* OS: More than one CLI (command line interpreter) a.k.a. shell
may be available. What they do with the remainder of the command line
after the pathname of the executable (binary program or script or
whatever) is up to them, but I have never seen any which would lump
space-separated tokens into one arg without some quoting convention
having to be used.

Try this:
if __name__ == "__main__":
for num, arg in enumerate(sys.a rgv):
print "arg %d is %s" % (num, arg)

This should art least give you some hints...

BTW, isn't the DOS syntax for command line args something like :
myprog /arg1 /arg2


Which DOS do you mean? IBM DOS/VS? AmigaDOS? MS-DOS?

The likelihood is that the OP is not running any of these, but is
running a recent version of Windows. The standard CLI (cmd.exe) does use
a syntax for built-in commands where '/' is used for options where a *x
shell would use '-'; however this is sublimely irrelevant.

Python scripts get their args on Windows just like anywhere else. C
programs (like the excellent collection of GnuWin32 utilities) likewise
just do main(argc, argv) {blah; blah} and carry on regardless just as
K&R intended.
Aug 11 '05 #5
John Machin a écrit :
bruno modulix wrote:
(snip)

Nope. But since you're running this on a very peculiar OS, I just can
guess that this very peculiar OS consider all args to be one same
string...

NOT SO:


Your cap key got stuck ?

(snip)
For *any* OS: More than one CLI (command line interpreter) a.k.a. shell
may be available.
"may"...
BTW, I don't remember anything like a shell in MacOS 7... (please don't
tell me about AppleScript).
What they do with the remainder of the command line
after the pathname of the executable (binary program or script or
whatever) is up to them, but I have never seen any which would lump
space-separated tokens into one arg without some quoting convention
having to be used.
I guess I have had so frustrating experiences with Windows that I assume
that anything that goes against common sens can happen !-)

(snip)
BTW, isn't the DOS syntax for command line args something like :
myprog /arg1 /arg2


Which DOS do you mean? IBM DOS/VS? AmigaDOS? MS-DOS?


QDOS, of course !-)
The likelihood is that the OP is not running any of these, but is
running a recent version of Windows.
Yes. I meant the (hum) CLI interface - which is still called "the DOS"
by a lot of Windows users I know (at least those who already used MS-DOS
before Windows became an OS).
The standard CLI (cmd.exe) does use
a syntax for built-in commands where '/' is used for options where a *x
shell would use '-'; however this is sublimely irrelevant.
I like the use of "sublimely" in this context.
Python scripts get their args on Windows just like anywhere else.


Ever used Python on MacOS Classic ?
Ok, now we know that the CLI syntax is not the problem - which may be
useful for the OP, thanks John -, and that John Machin tend to be
somewhat reactive when one says that Windows is a somewhat peculiar OS -
which is not really a useful information, but what...
Aug 11 '05 #6
Daniel Schüle wrote:
I just tried the same code at home and it worked fine
it has to do with windows .. some settings or whatever
(python 2.4.1 installed on both)

maybe someone have experienced the same problem
and had more luck in solving the puzzle


First of all: "Windows" is a whole family of OSes,
and not all members have any blood relations. The
NT family is probably more related to VMS than to
MS DOS.

Secondly: There is an association mechanism (I don't
have access to Windows at work, but you can find it
in some Explorer menu) where you define what the OS
does when you try to fire off a file with a certain
extension. That mechanism defines if and how the OS
passes command line arguments.

It might we work better if you run "python x.py y z"
instead of just "x.py y z".

This might give a hint...
http://www.robvanderwoude.com/call.html
Aug 12 '05 #7
> Nope. But since you're running this on a very peculiar OS, I just can
guess that this very peculiar OS consider all args to be one same string...
It depends on what you're coding with. If you're writing a Win32
program in C/C++ (and by extension, Visual Basic), the WinMain()
function passes all of the arguments in a single string. One of the
many stunningly boneheaded Win32 decisions, IMNSHO.
BTW, isn't the DOS syntax for command line args something like :
myprog /arg1 /arg2


No, by convention only, the "switch" character for DOS programs is "/"
instead of "-" or "--". Personally, I'm of the opinion that this
switch convention, backslashes in paths, and two-byte newlines are all
intentionally designed to make things LESS compatibile with other OSes,
and MORE difficult to interoperate.

Aug 12 '05 #8
It might make more sense if you could find out exactly what that one
argument contains.

Aug 12 '05 #9
Daniel Schüle <uv**@rz.uni-karlsruhe.de> wrote:

I just tried the same code at home and it worked fine
it has to do with windows .. some settings or whatever
(python 2.4.1 installed on both)

maybe someone have experienced the same problem
and had more luck in solving the puzzle


It's an installation problem, or maybe you tried to "fix" the installation
yourself. I will wager real money that it works if you say this:
python vhd2h.py vhd.vhd vhd.h -o

When you omit the "python" name, the operating system has to figure out how
to run the command. It does that by looking the extension up in the
registry, finding the command to run.

In a CMD shell, do this:

c:\tmp> assoc .py
.py=Python.File

c:\tmp> ftype Python.File
I'm guessing yours will print something like this:
Python.File=c:\ Python24\python 24.exe %1

The %1 is substituted with the name of the script being run. In this
example, however, the parameters are all discarded. If you set this
instead:

c:\tmp> ftype Python.File=c:\ python24\python 23.exe "%1" "%*"

The "%*" says "put the rest of the parameters here."
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Aug 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
88303
by: Ivan Voras | last post by:
In a code such as: if len(sys.argv) < 2: print "I need arguments!" sys.exit(1) Is sys.exit() really a good choice? Is there something more elegant? (I tried return but it is valid only in a function)
1
4173
by: Stuart D. Gathman | last post by:
I need to be able to obtain the real argv (not the script name). The application is writing a CUPS backend in python. For some reason, CUPS decided to pass the URI as argv (perhaps to ensure that CUPS will only ever run on Unix, since CUPS stands for Common *Unix* Printing System). The only solution I can think of is to write a C wrapper that inserts the original argv before execing python with the script. Is there already a way to do...
9
2440
by: Amir Dekel | last post by:
Hi everyone, I have two problems: 1. How can I keep my changes in sys.path after closing the interpreter? 2. os.path.expanduser("~") always gives me "C:\\" instead of my homepath. I have tried to change my homepath in WinXP using set homepath(in command line), and alsaw using the "Environment Variables" in WinXP system properties, non helped. I really have to fix this somehow.
14
39794
by: Hal Styli | last post by:
Is this a style thing? int main(int argc, char *argv ) or int main(int argc, char **argv ) i.e. *argv or **argv Why choose the latter?
0
971
by: Josh Taylor | last post by:
I have a class that wraps a large file and tries to make it look like a string w.r.t. slicing. Here, "large file" means on the order of hundreds of GB. All the slicing/indexing stuff through __getitem__() works fine, but len() is quite broken. It seems to be converting the value returned by __len__() to a 32-bit integer. If the conversion yields a negative number, it raises an exception. I'm running Python 2.4.1 on an Opteron running...
4
1196
by: Ravikumar | last post by:
Hi All, The following code snippet is a part of s/w which is downloaded from net. While compiling this code I got the following error. ...\..\snmplib\snmpTCPDomain.c(6) : fatal error C1083: Cannot open include file: 'sys/socket.h': No such file or directory NMAKE : fatal error U1077: 'cl.exe' : return code '0x2' Stop. NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3\VC98\BIN\NMAKE.EXE' :
25
5843
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
4
2300
Deathwing
by: Deathwing | last post by:
Hi can any one tell what is wrong with this code, whenever I enter two arguments I still get my error message that i must enter at least two arguments. Here is the code. #command line arguments import sys if len(sys.argv)!=2: sys.exit("You must enter at least 2 values.")
1
6839
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send mail externally to a internet email site like Gmail the PDF is sent but is corrupted because CDOSYS ends up using binary encoding rather than Base64 encoding when creating the attachment. More information here: Anthonys Code My knowledge of ASP...
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.