python的文件读写问题?
阿神
阿神 2017-04-18 10:32:46
0
4
555
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

什么情况呢?

阿神
阿神

闭关修行中......

reply all(4)
阿神

Your python version should be 2.X, right? Please try changing 'rw' in the permissions section to 'r+'

洪涛

As long as you bring the + sign, you will have various permissions.

洪涛

rw cannot be recognized. If you want to have both read and write permissions, you can change it to ab+

巴扎黑

It is recommended to use with to improve code readability

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!