Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

file_object = open(r"/root/py_test/web01/src/ftime",'rw')
try:
    print file_object.read()
    file_object.write('test')
finally:
    file_object.close( )

读取一个文件,内容就一行
然后再写入,报错。

IOError
IOError: [Errno 9] Bad file descriptor

什么情况呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
99 views
Welcome To Ask or Share your Answers For Others

1 Answer

你的python版本应该是2.X吧?请试试把权限部分的'rw'改成'r+'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...