A Simple Logger Class : Class Constructor : Class : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  Class   » [  Class Constructor  ]  Screenshots 
 



A Simple Logger Class



import time

class Logger:
    def __init__(self, filename):
        self.filename = filename
    def __call__(self, string):
        file = open(self.filename, 'a')
        file.write('[' + time.asctime() '] ')
        file.write(string + '\n')
        file.close()

log = Logger('logfile.txt')


log('Starting program')

log('Trying to divide by 0')

print 0

log('The division succeeded')

log('Ending program')

           
       
Related examples in the same category
1.  Empty Class constructor
2.  Constructors Demo Constructors Demo
3.  A class may define a special method named __init__() A class may define a special method named __init__()
4.  A very simple class with a constructor. A very simple class with a constructor.
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.