python "r+" requires file to exist?
I know that it doesn't make sense to open file for reading if it doesn't exist, unlike for writing. But I need to create a file object, wr开发者_如何学Pythonite data to it and then read it later, that's why I want to use the "r+" mode. Of course I can just open the file for writing once and then open the saved file for reading, but the problem is I don't want the file to be saved to disc. Any ideas?
Maybe you should be using a StringIO then. It imitates file-like operations (such as writing to and reading from it).
精彩评论