我如何 运行 没有 .py 扩展名的 argparse python 程序?
How can I run an argparse python program without the .py extension?
目前,我必须输入 /xkcdpwgen.py -h
才能获得以下内容
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)
但是,我希望能够键入 /xkcdpwgen -h
并获得以下内容
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)
相反,我得到以下内容
bash: ./xkcdpwgen: No such file or directory
你可以随意命名;只要 she-bang 行(例如 #!/bin/python
)是好的,那么文件就会 运行.
$ mv xkcdpwgen.py xkcdpwgen
$ ./xkcdpwgen -h
有关详细信息:shebang 维基百科
目前,我必须输入 /xkcdpwgen.py -h
才能获得以下内容
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)
但是,我希望能够键入 /xkcdpwgen -h
并获得以下内容
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)
相反,我得到以下内容
bash: ./xkcdpwgen: No such file or directory
你可以随意命名;只要 she-bang 行(例如 #!/bin/python
)是好的,那么文件就会 运行.
$ mv xkcdpwgen.py xkcdpwgen
$ ./xkcdpwgen -h
有关详细信息:shebang 维基百科