473,473 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 733

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris... | last post by:
Two simple questions regarding future of Python: 1) Is there already a "fix" to avoid writing to an attribute that isn't defined yet? I remember this being an often discussed problem, but...
9
by: úÁÕÒ ûÉÂÚÕÈÏ× | last post by:
There is a syntactic sugar for item access in dictionaries and sequences: o = v <-> o.__setitem__(e, v) o <-> o.__getitem__(e) where e is an expression. There is no similar way for set/get...
5
by: Joel Andres Granados | last post by:
Hi list: I have googled quite a bit on this matter and I can't seem to find what I need (I think Im just looking where I'm not suppose to :). I'm working with code that is not of my authorship...
12
by: Joshua Kugler | last post by:
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.