开发者

python "r+" requires file to exist?

开发者 https://www.devze.com 2023-03-20 10:57 出处:网络
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, th

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消