(newbie) class with a single instance ?!

Andrea Tomadin tom.and at tiscalinet.it
Fri Dec 15 13:57:18 EST 2006


Hi,
I need a suggestion on the better implementation for a very basic task.

I run a program which does some logging on files. I want to collect  
all the filenames and handlers in the same structure. All the files  
should be opened at startup, closed at exit, and easily accessed by  
the rest of the script.

I thought of writing a class with the file handlers as objects and  
opening and closing operations within __init__ and __del__. Then an  
instance of the class is created at the beginning of the program and  
used.

This works, but isn't it weird to define a class if I know from the  
very beginning that there will be no more than an instance of that  
class?

Suggestions on this basic OOP task are very appreciated!
Thank you,

Andrea




More information about the Python-list mailing list