1. 模拟C语言得到int main(int argc, char* argv)的参数:
import sys
if __name__ == '__main__':
a = list(range(0,len(sys.argv)));
for num in a:
print('argc[',num ,']: ',sys.argv[num])
输入: python tspy.py 1, 2 3 aaa bb c d
结果输出:
argc[ 0 ]: C:\Users\ABC\Desktop\tspy.py
argc[ 1 ]: 1,
argc[ 2 ]: 2
argc[ 3 ]: 3
argc[ 4 ]: aaa
argc[ 5 ]: bb
argc[ 6 ]: c
argc[ 7 ]: d