WANT: bad code in python (for refactoring example)

alister alister.ware at ntlworld.com
Thu Feb 16 09:18:17 EST 2017


On Thu, 16 Feb 2017 12:00:36 +0100, Cecil Westerhof wrote:

> On Thursday 16 Feb 2017 10:43 CET, alister wrote:
> 
>> On Wed, 15 Feb 2017 19:08:59 -0800, Paul Rubin wrote:
>>
>>> Antoon Pardon <antoon.pardon at rece.vub.ac.be> writes:
>>>> On reason to use this is for some easy "logging"
>>>
>>> I think it's better to use the actual logging module. I generally
>>> start a new program with print statements but convert them to logging
>>> after there's enough code to want to be more organized about it.
>>
>> my default python template file includes basic logging setup from the
>> start (all 3 lines of it )
> 
> You should have shared your template, or at least those three lines.
> :-P

import logging
logger=logging.getLogger()
logging.basicConfig(level=logging.DEBUG)

now simply add logger.debug('debug message')
wherever needed instead of print statements

alternatively
import logging
logger=logging.getLogger()
logging.basicConfig(filename='logfile',level=logging.DEBUG)

if you would prefer to log to a file instead.

simples :-)



-- 
A New Way of Taking Pills
	A physician one night in Wisconsin being disturbed by a burglar, 
and
having no ball or shot for his pistol, noiselessly loaded the weapon with
small, hard pills, and gave the intruder a "prescription" which he thinks
will go far towards curing the rascal of a very bad ailment.
		-- Nevada Morning Transcript, January 30, 1861



More information about the Python-list mailing list