![](https://secure.gravatar.com/avatar/400c33ea93f52b90b51859901fd88a92.jpg?s=120&d=mm&r=g)
On 24Nov2021 19:26, Eyal Gruss <eyalgruss@gmail.com> wrote:
i find myself changing all my print()'s to custom myprint()'s.
Had you tried: from myutils import myprint as print I've got a terminal status line module (cs.upd), and to print things one needs to withdraw the status lines, run the normal print(), restore the lines (or nip to the top status line, insert a blank, run the normal print, redraw below it). This approach lets one interoperate with code already using print() without changing that code.
4. add to the standard io library a new class which gives you the write interface of a single stream, but is a wrapper that will write to multiple streams:
with open('output.txt', 'w') as f: multi = io.OutputStreamCollection(sys.stdout, f) multi.write('hello\n') # or: print('hello', file=multi)
I've got one of those in my cs.fileutils module, a Tee(*files) class and a tee(file1, file2) context manager. I find I pretty much never use them. While that's unfair to you, since you seem to have this situation, it is to me an argument that such a thing does not need to be in the stdlib. You mentioned logging. Doesn't just adding a second root logger (or handler) get you what you'd want there? They accumulate, and messages go to all lthe loggers. BTW, can you elaborate on when you find yourself wanting to write the same message t multiple files? Other than logging, I've almost never wanted to do that. Cheers, Cameron Simpson <cs@cskk.id.au>