天天看点

代码练习,字符替换

f = open(file='兼职utf8.txt',mode='r+',encoding='utf-8')

data= f.read() #读取

old = '北京'

new = '上海'

data= data.replace(old,new)

f.seek(0)

f.write(data)