Rich G.
Rich G.

Reputation: 61

Replace wx.PyLog with what?

I'm porting some Python code from 2.7 to 3.x. The original code fails with this error:

class myTextLog(wx.PyLog):
AttributeError: 'module' object has no attribute 'PyLog'

When checking for the presence of wx.PyLog it is indeed not there:

>>> import wx
>>> wx.PyLog
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PyLog'
>>> wx.version()
u'4.1.0 msw (phoenix) wxWidgets 3.1.4'

When I check for the presence of wx.PyLog in an older version of wx, it is there:

>>> import wx
>>> wx.PyLog
<class 'wx._misc.PyLog'>
>>> wx._misc
<module 'wx._misc' from '/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/_misc.pyc'>
>>> wx.version()
'3.0.2.0 gtk2 (classic)'

I see it being used in this old sample code: http://www2.geog.ucl.ac.uk/~plewis/bpms/src/start/Main.py

#---------------------------------------------------------------------------
# Show how to derive a custom wxLog class

class MyLog(wx.PyLog):
    def __init__(self, textCtrl, logTime=0):
        wx.PyLog.__init__(self)
        self.tc = textCtrl
        self.logTime = logTime

    def DoLogString(self, message, timeStamp):
        #print message, timeStamp
        #if self.logTime:
        #    message = time.strftime("%X", time.localtime(timeStamp)) + \
        #              ": " + message
        if self.tc:
            self.tc.AppendText(message + '\n')

Somewhere along the line it appears to have been removed. What would be a suitable replacement for the code above given wx.PyLog is no longer available?

Upvotes: 0

Views: 210

Answers (1)

Dan A.S.
Dan A.S.

Reputation: 711

In python 3.x you should use: logging

You will want to take a look at Logging HOWTO

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')

Upvotes: 2

Related Questions