Python file modes detail

后端 未结 3 1026
轻奢々
轻奢々 2021-02-03 10:28

In Python, the following statements do not work:

f = open(\"ftmp\", \"rw\")
print >> f, \"python\"

I get the error:

Trace         


        
3条回答
  •  日久生厌
    2021-02-03 11:13

    Better yet, let the documentation do it for you: http://docs.python.org/library/functions.html#open. Your issue in the question is that there is no "rw" mode... you probably want 'r+' as you wrote (or 'a+' if the file does not yet exist).

提交回复
热议问题