import sys
if __name__ == '__main__':
print(sys.argv)
if sys.argv[1]== None:
print('taking default file 15.wav')
else:
print('taking the given specified file:')
print(sys.argv[1])
这不行,如何检查如果给定文件,程序是否会处理指定的文件?
像这样。
# no file given as arg, so
# the below will work on default 15.wav file
python program.py
python program.py 4.wav #this will work on 4.wav
试试这样。
import sys
if __name__ == '__main__':
if len (sys.argv) > 1 :
print('taking the given specified file:', sys.argv [1])
else :
print('taking default file 15.wav')