How to get class's name on runtime?

Järvinen Petri jarvin24 at lehtori.cc.tut.fi
Thu May 9 04:08:23 EDT 2002


Hey again

This must have been asked several times, but I'll give my try :)

How can I get class-instances name at runtime?

I have tried to use __name__ method, but that does not exist...

I have tried...

------------

class parameterMissing(Exception):
    def __init__(self,desc):
        self.desc = desc
        self.raisedTime = currentTime()
                
        #inform log that exception was raised
        enactLog.exceptionRaised(self)
        #inform log that some script failed
        enactLog.scriptFailed(self)
        
    # logMessage returns the message that should be wrote to correct 
    #  logfile by enactLog-module.
    
    def logMessage(self):
        return self.__name__ + ' was raised at ' + self.raisedTime + '. 
               Message was: ' + self.desc

And that self.__name__ sais that instance has no attribute __name__


Might be stupid question, but thanks anyway..

- Petri



More information about the Python-list mailing list