REPOST: Re: Help - command line arguments
Emile van Sebille
emile at fenx.com
Sun Dec 30 00:42:05 EST 2001
More information about the Python-list mailing list
Sun Dec 30 00:42:05 EST 2001
- Previous message (by thread): REPOST: Re: Help - command line arguments
- Next message (by thread): REPOST: Re: Help - command line arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Steve Zatz" <slzatz at hotmail.com> wrote in message news:YpxX7.242028$bs2.45285312 at news02.optonline.net... > I am new to Python and although I am sure that the following is obvious I > can't figure the following out or find an answer in any of the texts that I > have access to. > > My question is: Can you run a script that takes command line arguments from > within the Python shell or from the Python command line? > > For example, something like: > > test.py -a -b > > runs fine from the *Windows XP* command prompt. > > From the Python command line, I can do the following: > > import test > test.main() > > which doesn't produce an exception but I can't figure out how to input the > command line arguments. > > And from the Python Shell, just running test.main() produces a getopt > exception which does not occur when it runs from the Python command line. > (But in either case, I can't figure out how to use command line arguments.) > > Again, any help would be appreciated. Thanks. > > > C:\>type test.py import sys print sys.argv C:\>python -c "import os; print os.popen('test.py passed_arg').read()" ['C:\\test.py', 'passed_arg'] Or you could force sys.argv appropriately: import test import sys sys.argv = [test.__file__, 'my_argv1', 'etc...'] test.main() HTH, -- Emile van Sebille emile at fenx.com --------- ========= WAS CANCELLED BY =======: Path: news.sol.net!spool0-nwblwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!news.maxwell.syr.edu!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r From: "Emile van Sebille" <emile at fenx.com> Newsgroups: comp.lang.python Subject: cmsg cancel <a0m9or$l6pb9$1 at ID-11957.news.dfncis.de> Control: cancel <a0m9or$l6pb9$1 at ID-11957.news.dfncis.de> Date: Mon, 31 Dec 2001 02:37:25 GMT Organization: A poorly-installed InterNetNews site Lines: 2 Message-ID: <cancel.a0m9or$l6pb9$1 at ID-11957.news.dfncis.de> NNTP-Posting-Host: 211.57.49.2 X-Trace: news2.kornet.net 1009774372 27193 211.57.49.2 (31 Dec 2001 04:52:52 GMT) X-Complaints-To: usenet at news2.kornet.net NNTP-Posting-Date: Mon, 31 Dec 2001 04:52:52 +0000 (UTC) X-No-Archive: yes X-Unac4ncel: yes X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999) This message was cancelled from within Mozilla.
- Previous message (by thread): REPOST: Re: Help - command line arguments
- Next message (by thread): REPOST: Re: Help - command line arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list