Skip to content
Advertisement

How can I run an argparse python program without the .py extension?

Currently, I have to type /xkcdpwgen.py -h in order to get the following

usage: xkcdpwgen [-h] [-w WORDS] [-c CAPS] [-n NUMBERS] [-s SYMBOLS]

Generate a secure, memorable password using the XKCD method

optional arguments: -h, –help show this help message and exit -w WORDS, –words WORDS include WORDS words in the password (default=4) -c CAPS, –caps CAPS capitalize the first letter of CAPS random words (default=0) -n NUMBERS, –numbers NUMBERS insert NUMBERS random numbers in the password (default=0) -s SYMBOLS, –symbols SYMBOLS insert SYMBOLS random symbols in the password (default=0)

But, I want to be able to type /xkcdpwgen -h and get the following

usage: xkcdpwgen.py [-h] [-w WORDS] [-c CAPS] [-n NUMBERS] [-s SYMBOLS]

Generate a secure, memorable password using the XKCD method

optional arguments: -h, –help show this help message and exit -w WORDS, –words WORDS include WORDS words in the password (default=4) -c CAPS, –caps CAPS capitalize the first letter of CAPS random words (default=0) -n NUMBERS, –numbers NUMBERS insert NUMBERS random numbers in the password (default=0) -s SYMBOLS, –symbols SYMBOLS insert SYMBOLS random symbols in the password (default=0)

Instead, I get the following

bash: ./xkcdpwgen: No such file or directory

Advertisement

Answer

You can name it whatever you’d like; as long as the she-bang line (e.g. #!/bin/python) is good, then the file will run.

$ mv xkcdpwgen.py xkcdpwgen
$ ./xkcdpwgen -h

For more info: shebang on Wikipedia

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement