Python write file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
f = open("out.txt", "a")
for i in range(1,102):
# something before write here
if i<10:
f.write("00")
f.write(str(i))
f.write(".jpg\n")
elif i<100:
f.write("0")
f.write(str(i))
f.write(".jpg\n")
else:
f.write(str(i))
f.write(".jpg\n")
f.close()
  • open file get a file variable
  • write data from range of int
  • after written close file

string -> char bunch slice method
target = src[0:len(src)-5]