1 #demo.py 2 #!/usr/bin/python 3 import sys 4 5 print sys.argv
#python demo.py 11 22 33 44 55
[‘demo.py‘, ‘11‘, ‘22‘, ‘33‘, ‘55‘]
可见,sys.argv是一个list,并且sys.argv[0]是文件名;
文件操作:
1 [email protected]:~/cp# python demo.py 11 2 [‘demo.py‘, 11] 3 #!/usr/bin/python 4 #encoding=utf-8 5 import sys 6 7 print sys.argv 8 9 fd = open(‘./demo.py‘, ‘r‘) 10 while True: 11 line = fd.readline() 12 if not line: 13 break 14 line = line[:-1] #有换行符,注意去掉最后一个字符 15 print line
时间: 2024-09-28 22:50:35