开发者

represent a file as an object with python

Questions: How do you represent a file in python as an object, entirely in memory, making no calls to the hard drive?


Info:

I'm working on a project that has files distributed across many computers at once, these files are all stored in a SQLite3 database with identifiers so that the files can be keep in sync and I only have to have 1 file to deal with on the computers rather than many.

My problem is that the "open" command requires a path on the hard drive. well that path doesn't exist. I still need to be able to interact with these file o开发者_运维问答bjects though. What I'm looking for is a way to interact with these files as if they were on the hard drive, but they are only in memory, probably as a byte string. so kind like if i were to go:

file = open(<location in memory>,'r')

I've tried searching for this, but all search results just point to streaming files from the hard drive. so just to make this clear, I am no streaming from the hard drive, and that is not an option. If I have to do that, I'll rework my system for that. but right now that is an extra pointless step.


Take a look at the StringIO (and cStringIO) module: http://docs.python.org/library/stringio.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜