what is needed is a new kind of file-like class for buffering with sensible semantics more like a pipe. when created, it will have two file-like interfaces, one for writing, and one for reading. after data is written to the write side, some or all of it can be read. if a
additional methods could do:
peek() can see all the data that has be written but not yet read
unread() can push data back in, in reverse order
reset() can make it empty and ready to write, again
features can be added to special implementations:
operate over system piper if a fork() is done
testers can simulate data delays, mangled data, lost data, etc.
this is the kind of thing i have already been doing. the function takes an argument of a file-like object to write to. so i have already written to a file and read it back. i am seeking something faster with less overhead
flush()
is done on the write side then all (as opposed to some or all) of the data written before the flush()
can be read. after a close()
is done on the write side, any resources needed for writing can be released, but the written data is not released. data can still be read if it has not been read, yet. after data is read, then it is no longer readable and can be released. after close()
on the write interface, no more data can be written, after close()
on the read interface, no more data can be read. data can be read both before closing the write interface and after.additional methods could do:
peek() can see all the data that has be written but not yet read
unread() can push data back in, in reverse order
reset() can make it empty and ready to write, again
features can be added to special implementations:
operate over system piper if a fork() is done
testers can simulate data delays, mangled data, lost data, etc.
(Apr-25-2017, 06:58 AM)wavic Wrote:import sys stdout_bak = sys.stdout with open('output.txt', 'w') as sys.stdout: print("I've never did this before so now I'm experimenting") print("After that output.txt should containd this prints") sys.stdout = stdout_bak # you must return everything as it was before to print normally again print('After the first with statement') with open('output.txt', 'r') as in_file: print(in_file.read())
Output:victor@jerry:~$ python3 /tmp/test.py After the first with statement I've never did this before so now I'm experimenting After that output.txt should containd this prints
this is the kind of thing i have already been doing. the function takes an argument of a file-like object to write to. so i have already written to a file and read it back. i am seeking something faster with less overhead
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.