Present file as object with python

Questions: How do you present a file in python as an object, completely in memory, do not make any calls to the hard drive?


Information:

I am working on a project that has files distributed on many computers at the same time, these files are stored in the SQLite3 database with identifiers, so the files can be synchronized, and I need to have only one file on computers, and not on many.

My problem is that the "open" command requires a path on the hard drive. it’s good that the path does not exist. However, I still need to be able to interact with these file objects. I am looking for a way to interact with these files as if they were on the hard drive, but they are only in memory, possibly in the form of a byte string. so kindly if I were to go:

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

I tried looking for this, but all the search results just point to streaming files from the hard drive. therefore, just to make it clear, I am not moving from the hard drive, and this is not an option. If I have to do this, I will redesign my system for this. but now this is an extra pointless step.

+3
source share

Source: https://habr.com/ru/post/1782016/


All Articles