import getopt
import sys
def usage():
print 'this is a usage.'
def main():
try:
print sys.argv
#sys.argv[0],表示文件路径,sys.argv[1:],表示用户输入所有参数
#hp:i, 带有:表示需要跟参数,后面的长参数需要带‘=’
options,args = getopt.getopt(sys.argv[1:],"hp:i:",["help","ip=","port="])
print 'options:',options
print 'args:',args
except getopt.GetoptError:
sys.exit() print '--------------------' for name,value in options:
if name in ("-h","--help"):
usage()
if name in ("-i","--ip"):
print 'ip is----',value
if name in ("-p","--port"):
print 'port is----',value if __name__ == "__main__":
main()
相关文章
- 09-28python导入包失败ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib'
- 09-28python-为什么无法使用“ from module import *”从模块导入此装饰器?
- 09-28Python 模块(module)
- 09-28python – sniffer找不到DJANGO_SETTINGS_MODULE
- 09-28python3 module中__init__.py的需要注意的地方
- 09-28Python报错——module 'scipy.misc' has no attribute 'imresize'
- 09-28pip3安装的module无法导入python3
- 09-28WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is
- 09-28python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
- 09-28Python “No module named” 以及在Python2中可以导入,但在python3中却出现的原因