problem with an infinite loop
dj trombley
badzen at yifan.net
Fri Dec 17 02:23:32 EST 1999
Ionel Simionescu wrote:
>
> Hi,
>
> The code below represents an erroneous snippet that crashes Python
> (1.5.2/WinNT) in a very reproductible manner.
>
> Maybe this kind of error can be intercepted by the interpreter and raise an
> exception.
>
> ionel
>
> ---
>
> # I know this code is bad.
>
> class node:
> def __init__(self, name=''):
> self.name = name
>
> def __setattr__(self, name, value):
> if name=='name': self.name = value
>
> f = node()
The answer here is to not assign to an attribute in the usual fashion,
ie. <object>.<name>,
but to directly access the object's dictionary.
For example:
if name == 'name':
self.__dict__[name] = value
-dj
Dave Trombley
<badzen at yifan.net>
More information about the Python-list
mailing list