[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: WANT: bad code in python (for refactoring example)
From: Antoon Pardon <antoon.pardon () rece ! vub ! ac ! be>
Date: 2017-02-15 13:37:23
Message-ID: 1064aa40-072f-f8c4-2488-fd80b46f0c08 () rece ! vub ! ac ! be
[Download RAW message or body]
Op 15-02-17 om 13:24 schreef Steve D'Aprano:
> On Wed, 15 Feb 2017 09:49 pm, Antoon Pardon wrote:
>
>> Op 15-02-17 om 07:28 schreef Steven D'Aprano:
> [...]
>>> Why not use sys.stdout.write directly? Or print? If I saw somebody using
>>> this recipe in production code, in the way shown, I'd refactor it to just
>>> use print. There's no advantage to re-inventing the wheel this way.
>> On reason to use this is for some easy "logging", you use echo to help
>> in debugging and afterwards you can either define echo as an empty
>> function or something easy to find to comment out.
> In Python 3 you can always add
>
> def print(*args, **kw):
> pass
>
> in your module to disable printing. But a better way, in my opinion, is to
> use your editor to search for:
>
> print(
>
> and replace with:
>
> #print(
You don't seem to understand, I don't want to disable all printing, only the
diagnostics. That is easier to do if I use a different name for printing
diagnostics than for regular I/O. Whether I disable it by defining an empty
function or by commenting them out, doesn't really matter with this regard.
> But even better, once you get to the point of putting print calls in more
> than two or three places in your code, you should probably invest the time
> to learn how to use the logging module.
I know how to use the logging module. It is my experience that for a lot
of rather small projects, the hassle of setting it up, is not worth it.
YMMV.
--
Antoon Pardon
--
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic