python 文件读写
2021-06-18 02:03
阅读:805
标签:write close 读取文件 txt str 一个 file des content
读写文件3个步骤
- 调用open()函数,返回一个File对象
- 调用File对象的read()或write()方法
- 调用File对象的close()方法,关闭该文件
读取文件:
- helloFile = open(‘C:\\Users\\Administrator\\Desktop\\url.txt‘)
- helloContent = helloFile.read()
- helloFile.close()
写入文件
- helloFile = open(‘C:\\Users\\Administrator\\Desktop\\url.txt‘, ‘w‘)
- helloFile.write(‘Hello world!\n‘)
- helloFile.close()
python 文件读写
标签:write close 读取文件 txt str 一个 file des content
原文地址:https://www.cnblogs.com/luckyls/p/9718607.html
评论
亲,登录后才可以留言!