2018-02-07

2018-02-07  本文已影响0人  ppying

Python文件操作
打开文件并读取内容

file1 = open(file='abc', encoding='utf8')
contents = file1.read()
print(contents)
file1.close()

file_name = 'pi'

with open('pi', 'w', encoding='utf8') as file_object:
file_object.write('hello word\n')
file_object.write('hello word\n')
file_object.write('hello word\n')

上一篇下一篇

猜你喜欢

热点阅读