Use "Fire" module to input arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
python3 "file.py" -arg arg | |
''' | |
#install fire | |
pip install fire | |
#Main code | |
import fire | |
def printHelloWorld(): | |
return 'Hello World!' | |
def name(name): | |
return 'your name is {}.'.format(name) | |
if __name__ == '__main__': | |
fire.Fire() #使用fire.Fire()啟動Fire模組 | |
''' | |
Example1: | |
$ python fire_test.py name "Bob | |
Output: | |
your name is Bob | |
Example2: | |
$ python fire_test.py printHelloWorld | |
Output: | |
Hello World! | |
'''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment