Creating a custom file like a python object suggestion?

Hi, I am looking to implement my own custom file, such as an object, for the internal binary format we use at work (I really don't want to go into details because I don't know if I can do this). I am trying to go for a more pythonic way of doing things, as we currently have two read / write functions (each ~ 4k lines of code) that do everything. However, we need more control / refinement, therefore, the fact that I am rewriting this material.

I looked at the python documentation and they say which methods I need to implement, but don't mention things like iter () / etc.

Basically what I would like to do is things like this:

output_file_objs = [
    open("blah.txt", "w")
    open("blah142.txt", "wb")
    my_lib.open("internal_file.something", "wb", ignore_something=True)
]

data_to_write = <data>

for f in output_file_objs:
    f.write(data_to_write)

, . , .

- , ? (iter). ?

python, ?

+5
2

, "", , ; ( ).

, file iterator - , .

+4

StringIO? , . , Python , (, tell()) , .

0

All Articles