seek(), then read(), then write() in python

后端 未结 3 1792
轮回少年
轮回少年 2021-01-12 14:02

When running the following python code:

>>> f = open(r\"myfile.txt\", \"a+\")        
>>> f.seek(-1,2)                                              


        
3条回答
  •  失恋的感觉
    2021-01-12 14:26

    This appears to be a Windows-specific problem - see http://bugs.python.org/issue1521491 for a similar issue.

    Even better, a workaround given and explained at http://mail.python.org/pipermail/python-bugs-list/2005-August/029886.html, insert:

    f.seek(f.tell())
    

    between the read() and write() calls.

提交回复
热议问题