初学PYTHON遇到的小问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 22:37:01
>>> file=open('/tmp/haha.haha','w')
>>> file.read()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor

这是什么意思?

你打开一个写文件(w), 却尝试用read读取!

你的后缀名为什么是haha,一般open()被广泛用于打开文档文件,你的问题的open方程trace到的文件不是一个它可以识别并打开的文件。