文件的基本操作

一、打开文件

1.路径分隔符转义问题

① open(r'C:\a\nb\c\d.txt')

②open('C:/a/nb/c/d.txt')

2.打开方法

file1=open(r'aaa/a.txt',mode='rt')
#这里的file1是一个变量名,占用应用程序内存空间

3.操作文件

应用程序对文件的读写请求都是在向操作系统发送系统调用,然后由操作系统控制硬盘把输入读入内存、或者写入硬盘。
# 读
file1=open(r'aaa/a.txt',mode='rt')res=f.read()
print(type(res))

4.关闭文件

file1=open(r'aaa/a.txt',mode='rt')res=f.read()
print(type(res))
f.close()

posted @ 2020-03-13 18:08  江湖有梦  阅读(272)  评论(0编辑  收藏  举报