6fileobj=open('example-w.txt','w') ---> 7 cont = fileobj.read() 8print(cont) UnsupportedOperation:notreadable 可能原因: 1、打开example-w.txt是以只写方式打开的,再用read()方法读文件会报错。 解决方法: 1、如果文件只写入文件,不能使用read()方法。或者使用追加方式’a+’打开文件,可以先读文...
io.UnsupportedOperation: not readable python编程中老是这情况,是因为这个代码中有两处错误:1、你是用open打开一个文件,此时调用的是w写入模式,下面使用read是没有权限的。2、使用write写入一个字符s,但是此时并没有真正的写入,而是还存在与内存中。此时执行read读取的为空字符。需要先执行a.close...
File"<stdin>", line 1,in<module>io.UnsupportedOperation:notreadable>>> file = open('test1.py','r')#以只读打开文件>>> file.readline()#读取一行文件内容'hello python\n'>>>file.readline()'hello python\n'>>>file.readline()''>>> file.close()#关闭文件 2、文件对象的方法 f.read():读...
content = file.readline() # 读会报错 io.UnsupportedOperation: not readable file.close() 1. 2. 3. 4. 5. 6. # 2.1 用只读模式打开不存在的文件 file = open("b.txt","r") # 报错 FileNotFoundError: [Errno 2] No such file or directory: 'b.txt' file.close() 1. 2. 3. 4. # 2...
print(file1.read())#读取文件内容 file1.close() >>>报错 io.UnsupportedOperation: not readable在...
(1)<file>.read(size=-1) #从文件中读取整个文件内容,如果给出参数,读入前size长度的字符串(文本文件)或字节流(二进制文件),size=-1默认读取全部。 栗子1. #test2_1.py文件 with open("English_Study_Dict.txt",'rt') as file: a=file.readable() #判断文件是否可读取 b=file.writable() #判断文件...
# 1.2 用只写模式打开已存在的文件file = open("a.txt","w")file.write("123") # 写不会报错content = file.readline() # 读会报错 io.UnsupportedOperation: not readablefile.close() # 2.1 用只读模式打开不存在的文件file = open("b.txt","r") # 报错 FileNotFoundError: [Errno 2] No such...
io.UnsupportedOperation: not readable >>> file = open('test1.py','r') #以只读打开文件 >>> file.readline() #读取一行文件内容 'hello python\n' >>> file.readline() 'hello python\n' >>> file.readline() '' >>> file.close() #关闭文件 ...
r(默认参数): -只能读,不能写 -读取文件不存在 会报错 FileNotFoundError: [Errno 2] No such file or directory: '/tmp/westos' w(写) -write only -文件不存在的时候,会自动创建新的文件 -文件存在的时候,会清空文件内容并写入新的内容 a(追加): -write only -写:不会清空文件的内容,会在文件末尾...
python file文件操作--内置对象open 说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作。 2. file参数表示的需要打开文件的相对路径(当前工作目录)或者一个绝对路径,当传入路径不存在此文件会报错。或者传入文件的句柄。