本文整理汇总了Python中os.sys.argv方法的典型用法代码示例。如果您正苦于以下问题:Python sys.argv方法的具体用法?Python sys.argv怎么用?Python sys.argv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.sys
的用法示例。
在下文中一共展示了sys.argv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printUsage
# 需要导入模块: from os import sys [as 别名]
# 或者: from os.sys import argv [as 别名]
def printUsage():
print( 'Usage: python ' + sys.argv[0] + ' [options]' )
print( 'Options:' )
print( ' dir=[target directory]')
print( ' sets=[list of sets, eg: test,train10k,trainall. Available sets: test,train10k,trainall]')
示例2: processArgs
# 需要导入模块: from os import sys [as 别名]
# 或者: from os.sys import argv [as 别名]
def processArgs():
sTargetDirectory = 'data'
sets = [ 'test', 'train10k', 'trainall' ]
for arg in sys.argv[1:]:
splitarg = arg.split('=')
print( 'arg: [' + arg + ']' )
if( len(splitarg) != 2 ):
print('options should be provided in form [key]=[value], eg dir=data')
printUsage()
return
key = splitarg[0]
value = splitarg[1]
print('key: ' + key )
if key == 'dir':
sTargetDirectory = value
elif key == 'sets':
sets = value.split(',')
for thisset in sets:
if not thisset in ['test', 'train10k', 'trainall']:
print('unrecognized set: ' + thisset )
printUsage()
return
else:
print('unrecognized option ' + key )
printUsage()
return
print( 'target directory: ' + sTargetDirectory )
print( 'generate sets: ' + str( sets ) )
go(sTargetDirectory, sets)