Python dumps core with this.. how come?
Brad Howes
bradh at mediaone.net
Fri Jan 21 23:26:01 EST 2000
More information about the Python-list mailing list
Fri Jan 21 23:26:01 EST 2000
- Previous message (by thread): Minor inconsistency between cStringIO and (StringIO or normal fil es)...
- Next message (by thread): Python dumps core with this.. how come?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
katz at glue.umd.edu (Roey Katz) writes: <snip> > When I import this module, the interpreter segfaults. <snip> > class basic_monitor: > > def __init__( self ): > self.xres = [] # list of resource entries This is innocuous line is the start of your troubles. Below you declare __setattr__ which tells Python you want to handle all attributes settings for this instance. So... > def __setattr__( self, name, val ): > origval = self.res[ name ] But now you've asked for the attribute 'res' which has yet to be defined for this instance. You've declared __getattr__ which tells Python to call it when an attribute is not available (which it isn't yet) > def __getattr__( self, name ): > return self.res[ name ] Here, we try to get the same attribute Python failed to get. So, Python calls your hook again, and again, and again, until lack of stack tells Python to stop this silliness and to go get a beer. Since you've defined both hooks, you're going to have to work with the instance's attribute dictionary __dict__ dict = self.__dict__ and do your attribute setting using the usual dictionary methods (you could also declare "class" attributes with default values) That should keep Python up a bit longer. Brad -- Brad Howes C C++ HTML Java Python Waltham, MA Programmer "Were people this stupid before TV?" -- _White Noise_ by Don DeLillo
- Previous message (by thread): Minor inconsistency between cStringIO and (StringIO or normal fil es)...
- Next message (by thread): Python dumps core with this.. how come?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list