Carl Karsten wrote: > class dEvent(dObject): > ... > def __getattr__(self, att): > if self.EventData.has_key(att): > return self._eventData[att] > raise AttributeError, "%s.%s object has no attribute %s." % ( > self.__class__.__module__, self.__class__.__name__, > att) > > If this code is run as much as i think it is (I haven't tried to use any of > the > profiling tools yet) I bet things would speed up by replacing the if with a > try. > > something like: > > def __getattr__(self, att): > try: > return self._eventData[att] > except AttributeError: > raise AttributeError, "%s.%s object has no attribute %s." % ( > self.__class__.__module__, self.__class__.__name__, att) > > I am tempted to say just skip the try and let python raise the error - no > clue > what impact that would have on functionality. > > Carl K
Normally a try/except is more costly than a simple if. If you think that this code is run very often and wouldn't raise an exception too often, you would be right. If you still feel that it is worth the effort, please provide some profiling statistics to show that this would speed up a lot. If your speculations are right someone can change this quite fast. Uwe _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev Searchable Archives: http://leafe.com/archives/search/dabo-dev This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]
