471,049 Members | 1,306 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Re: Setting an attribute without calling __setattr__()


"Joshua Kugler" <jk*****@bigfoot.comwrote in message
news:fu**********@ger.gmane.org...
| OK, I'm sure the answer is staring me right in the face--whether that
answer
| be "you can't do that" or "here's the really easy way--but I am stuck.
I'm
| writing an object to proxy both lists (subscriptable iterables, really)
and
| dicts.
|
| My init lookslike this:
|
| def __init__(self, obj=None):
| if type(obj).__name__ in 'list|tuple|set|frozenset':
| self.me = []
| for v in obj:
| self.me.append(ObjectProxy(v))
| elif type(obj) == dict:
| self.me = {}
| for k,v in obj.items():
| self.me[k] = ObjectProxy(v)
|
| and I have a __setattr__ defined like so:
|
| def __setattr__(self, name, value):
| self.me[name] = ObjectProxy(value)
|
| You can probably see the problem.
|
| While doing an init, self.me = {} or self.me = [] calls __setattr__,
which
| then ends up in an infinite loop, and even it it succeeded
|
| self.me['me'] = {}
|
| is not what I wanted in the first place.
|
| Is there a way to define self.me without it firing __setattr__?

I believe self.__dict__['me'] = {} is one standard idiom.

Jun 27 '08 #1
0 669

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.