How to detect more argument parameters? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to detect more argument parameters?

victorti83plusvictorti83plus Posts: 24Member
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.

Comments

  • DrostDrost Posts: 24Member
    : 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
  • infidelinfidel Posts: 2,900Member
    : 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).


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.