[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:       jladasky () itu ! edu
Date:       2017-02-15 19:17:41
Message-ID: fe93ced0-f5a9-42e3-9eae-96a0da03327a () googlegroups ! com
[Download RAW message or body]

On Wednesday, February 15, 2017 at 2:52:55 AM UTC-8, Antoon Pardon wrote:
> Op 15-02-17 om 07:28 schreef Steven D'Aprano:

> > E.g. http://code.activestate.com/recipes/580750
> > 
> > does nothing more that define
> > 
> > echo = sys.stdout.write
> > 
> > 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.
> 
> -- 
> Antoon Pardon.

Agreed, I have done things like this myself, but within functions, not at the global \
level.  The "echo" name could be assigned to some other function elsewhere in the \
code.  I use the name reassignment to direct the function's logging information -- to \
                a console, to a GUI, or to "/dev/null" by creating an empty function.
-- 
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