[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:       Steve D'Aprano <steve+python () pearwood ! info>
Date:       2017-02-15 12:24:26
Message-ID: 58a4487c$0$1589$c3e8da3$5496439d () news ! astraweb ! com
[Download RAW message or body]

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(



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.




-- 
Steve
"Cheer up," they said, "things could be worse." So I cheered up, and sure
enough, things got worse.

-- 
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