马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 fc5igm 于 2021-6-8 22:48 编辑 >>> fgirl3=open(r'D:\python\works\girl_3.txt','w')
>>> girl.writelines(each[3:len(each)])
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
girl.writelines(each[3:len(each)])
ValueError: I/O operation on closed file.
>>> girl
<_io.TextIOWrapper name='D:\\python\\works\\girl_3.txt' mode='w' encoding='cp936'>
>>> each[3:len(each)]
':滚!!!'
>>> fgirl3.close()
>>> fgirl3=open(r'D:\python\works\girl_3.txt','w')
>>> girl.writelines(each[3:len(each)])
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
girl.writelines(each[3:len(each)])
ValueError: I/O operation on closed file.
>>> girl
<_io.TextIOWrapper name='D:\\python\\works\\girl_3.txt' mode='w' encoding='cp936'>
经查,该报错往往指缩进错误。但是问题是,我用的交互界面,根本没有缩进。怎么会缩进错误呢?
求问怎么解决
找到错误原因了>>> fgirl3.writelines(':滚!!!')
>>> girl
<_io.TextIOWrapper name='D:\\python\\works\\girl_3.txt' mode='w' encoding='cp936'>
>>> girl==fgirl3
False
>>> fgirl3
<_io.TextIOWrapper name='D:\\python\\works\\girl_3.txt' mode='w' encoding='cp936'>
>>> girl.writelines(':滚!!!')
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
girl.writelines(':滚!!!')
ValueError: I/O operation on closed file.
但是新的问题又来了。明明girl和fgirl3指代的完全一致,为什么girl会不等于fgirl3?
同样的指代内容,为什么fgirl3正确,girl就错误?
fgirl3和girl的原始赋值过程f=open(r'D:\python\works\record.txt')
fboy1=open(r'D:\python\works\boy_1.txt','w')
fboy2=open(r'D:\python\works\boy_2.txt','w')
fboy3=open(r'D:\python\works\boy_3.txt','w')
fgirl3=open(r'D:\python\works\girl_3.txt','w')
fgirl2=open(r'D:\python\works\girl_2.txt','w')
fgirl1=open(r'D:\python\works\girl_1.txt','w')
for num in range(3):
boy=[fboy1,fboy2,fboy3][num]
girl=[fgirl1,fgirl2,fgirl3][num]
-----------------------------------------------------------------------------------------------------------------------
原代码因为无法成功运行已经被我删掉了。用帖子中赋值相关的代码重复操作后,结果却又相等了。
可能是什么奇奇怪怪的bug吧。
发到python论坛,论坛对此的回复则是多变量对同文件的引用并不相等。
总之,因为原代码已经删除,也无法再重新验证了。不过我个人倾向于可能是发生了系统bug。
https://python-forum.io/thread-33900-post-143118.html |