本文整理匯總了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)