Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.