On 26Nov2021 16:00, eyalgr...@gmail.com <eyalgr...@gmail.com> wrote:
>i wonder whether:
>
>from myutils import myprint as print
>
>or
>
>_print = print
>print = myprint
>
>is really the pythonic way?

Well, I prefer the former - short and clear. You can always get the 
"old" print from the builtins module. In the setup above, myutils.print 
would do the _print=print shuffle in its implementation. In my own code 
that often looks like:

    from builtins import print as builtin_print

    def print(...):
        ... call buildin_print as needed ...

Then I import print from that module. Example:

    from cs.upd import Upd, print

"Upd" for the class the module provides, and print for the 
interoperating print() function from that module.

>my use case for multiple files on top of the stdout, is when using e.g. 
>wandb which is a popular ML dashboard and experiment logging platform. 
>i want to write my log file both the a local log.txt and to a second 
>copy in the temporary local wandb folder that later gets synced to the 
>cloud. otherwise i have to take care of copying over the file later 
>including in cases of exceptions. more generally: writing a log to both 
>a local and a remote location.

This sounds to me lke you want a logger setup with multiple handlers.  
Add a handler to log to your cloud log file in addition to the normal 
log file. Then you'd just use ordinary logging calls in your code 
elsewhere. No special print() at all.

Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/D2M737K63MH5YL6NLSV4G4HDLJT7BVER/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to