python 第三天
文件的修改操作
test = open = ('www.txt','r',encoding = 'utf-8') new_test = open = ('www.txt','w',encoding = 'utf-8') used = '北京' new = ‘广州’ for item in test: if '北京' in item: item = itrm.replace(used,new) new_test.write(item) test.close() new_test.close()
文件的高级操作
文件的读写操作 ‘’r+‘’
test = open('www.exe','w+')
文件的读写操作 ‘’w+‘’
test = open('www.exe','r+')
文件的读写操作 ‘’a+‘’
test = open('www.exe','a+')
f = test.readline(2) #默认写到文件后
f = test.tell #或取光标位置
f = test.seek #移动光标位置