command-line arguments
在命令行输入
python test.py 0 1 121
程序为
import sys
print(sys.argv)
print(len(sys.argv))
输出结果
["test.py", "0", "1", "121"]
4
如果想要移除第一个”test.py”,那么
sys.argv.remove(sys.argv[0])
之后print(sys.argv)得到
["0", "1", "121"]
文件的写操作
w –> write
r –> read
r+ –> read and write
a –> append
# Open a file
myFile = open("file.txt", "w")
# Show attributes and properties of that file
print(myFile.name)
print(myFile.mode)
输出结果为
file.txt
w
往文件里写东西
myFile.write("haha\n111111111111")
关闭流,好习惯
myFile.close()
文件的读操作
myFile = open("file.txt", 'r')
print(myFile.read())
输出结果为
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
读取出了文件里的所有内容
如果想要读前10个字符,那么
myFile = open("file.txt", 'r')
print(myFile.read(10))
打印结果为
50
51
52
5