Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to detect more argument parameters? Posted by victorti83plus on 18 Feb 2005 at 1:34 PM
Hi, I'm new to Python,

I don't know how to make my program detect some additional arg. parameters. For example, normally we type:

python filename.py

to run the program. But if we have additional parameter such as:

python filename.py -a

and I want my program to be able to detect that "-a" so it will perform some additional function. How do I do that? I try to find in google, but I couldn't find anything on that. So please help me >_<

Thx.
Report
Re: How to detect more argument parameters? Posted by Drost on 18 Feb 2005 at 3:47 PM
: Hi, I'm new to Python,
:
: I don't know how to make my program detect some additional arg. parameters. For example, normally we type:
:
: python filename.py
:
: to run the program. But if we have additional parameter such as:
:
: python filename.py -a
:
: and I want my program to be able to detect that "-a" so it will perform some additional function. How do I do that? I try to find in google, but I couldn't find anything on that. So please help me >_<
:
: Thx.
:

Just import the sys module and you'll have access to the command-line parameters through sys.argv. That'll be a list containing the script name as its first item (and thereafter the parameters if there were any).

Drost
Report
Re: How to detect more argument parameters? Posted by infidel on 22 Feb 2005 at 8:10 AM
: Just import the sys module and you'll have access to the command-line parameters through sys.argv. That'll be a list containing the script name as its first item (and thereafter the parameters if there were any).

Also look at the module documentation for the optparse module (also known as Optik before it became part of the standard library).


infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.