Python file operations

后端 未结 2 470
野趣味
野趣味 2020-11-27 07:03

I got an err \"IOError: [Errno 0] Error\" with this python program:

from sys import argv
file = open(\"test.txt\", \"a+\")
print file.tell() # not at the EOF         


        
2条回答
  •  时光说笑
    2020-11-27 07:50

    The solution is to use open from io

    D:\>python
    Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> f = open('file.txt','a+')
    >>> f.tell()
    0L
    >>> f.close()
    >>> from io import open
    >>> f = open('file.txt','a+')
    >>> f.tell()
    22L
    

提交回复
热议问题