Re: namespace dictionaries ok?

2005-10-26 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: >... > >> class namespace(dict): >> def __getattr__(self, name): >> return self.__getitem__(name) > >... > >>Any thoughts? Any better way to do this? > > > If any of the keys (which become attributes

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Grant Edwards
On 2005-10-26, Duncan Booth <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: > >> Uh, no. Isn't what we're doing here top-quoting? The quoted >> stuff is at the top. Everything is in chronological order. I >> think what you're referring to is "top-posting". > > Yes, Iain King already pointed th

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Duncan Booth
Grant Edwards wrote: > Uh, no. Isn't what we're doing here top-quoting? The quoted > stuff is at the top. Everything is in chronological order. I > think what you're referring to is "top-posting". Yes, Iain King already pointed this out. -- http://mail.python.org/mailman/listinfo/python-list

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Grant Edwards
On 2005-10-26, Duncan Booth <[EMAIL PROTECTED]> wrote: > James Stroud wrote: >> On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >>> P.S. James, *please* could you avoid top-quoting >> >> Were it not for Steve Holden's providing me with a link off the list, >> I would have never known to what

Re: namespace dictionaries ok?

2005-10-26 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: ... > class namespace(dict): > def __getattr__(self, name): > return self.__getitem__(name) ... > Any thoughts? Any better way to do this? If any of the keys (which become attributes through this trick) is named 'update', 'keys'

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Ron Adam
Duncan Booth wrote: > No, I didn't think it was malice which is why I just added what I > considered to be a polite request at the end of my message. I assumed that > most people either knew the phrase or could find out in a few seconds using > Google so there wasn't much point in rehashing t

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Iain King
Duncan Booth wrote: > James Stroud wrote: > > > On Tuesday 25 October 2005 00:31, Duncan Booth wrote: > >> P.S. James, *please* could you avoid top-quoting > > > > Were it not for Steve Holden's providing me with a link off the list, > > I would have never known to what it is you are referring. I

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Duncan Booth
James Stroud wrote: > On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> P.S. James, *please* could you avoid top-quoting > > Were it not for Steve Holden's providing me with a link off the list, > I would have never known to what it is you are referring. I have read > some relevant literat

Re: namespace dictionaries ok?

2005-10-25 Thread Simon Burton
In my case the deeply nested function calls are recursive calls for a tree traversal. This is similar to the visitor design pattern, where the Context class above is the Visitor. The difference is that the Context instance does not "visit" or "act" upon the nodes, but just stores state/context info

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 17:27:55 -0400, Mike Meyer wrote: >> On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> Their differences in styles, like mine, probably arise from the culture of >> their respective fields. Most, like me, may not even know what the heck you >> are talking about. Also,

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread Steve Holden
James Stroud wrote: > On Tuesday 25 October 2005 14:27, Mike Meyer wrote: > >>That's your right. Be aware that people will ignore, correct and/or >>complain about you doing so. > > > If I may be a complete ass: That should be "correct and/or complain about > *your* doing so." > You *may* be a

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread James Stroud
On Tuesday 25 October 2005 14:27, Mike Meyer wrote: > That's your right. Be aware that people will ignore, correct and/or > complain about you doing so. If I may be a complete ass: That should be "correct and/or complain about *your* doing so." James -- James Stroud UCLA-DOE Institute for Geno

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
Bengt Richter wrote: > On Tue, 25 Oct 2005 16:20:21 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >>Or worse, the dictionary would become not functional depending on what >>methods were masked. >> >> >>And this approach reverses that, The dict values will be masked by the >>methods, so the values c

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread Mike Meyer
> On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> P.S. James, *please* could you avoid top-quoting > James Stroud <[EMAIL PROTECTED]> writes: > I'm sorry if I can't find a dumb terminal for a "VAX" with which to read my > email. Perhaps, if i could, I would understand your frustration a l

Re: namespace dictionaries ok?

2005-10-25 Thread Bengt Richter
On Tue, 25 Oct 2005 16:20:21 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >Duncan Booth wrote: >> Ron Adam wrote: >> >>>James Stroud wrote: >>> Here it goes with a little less overhead: >> >> >> >>>But it's not a dictionary anymore so you can't use it in the same places >>>you would

Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread James Stroud
On Tuesday 25 October 2005 00:31, Duncan Booth wrote: > P.S. James, *please* could you avoid top-quoting Were it not for Steve Holden's providing me with a link off the list, I would have never known to what it is you are referring. I have read some relevant literature to find that this is more

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
Duncan Booth wrote: > Ron Adam wrote: > >>James Stroud wrote: >> >>>Here it goes with a little less overhead: >>> >>> > > > >>But it's not a dictionary anymore so you can't use it in the same places >>you would use a dictionary. >> >> foo(**n) >> >>Would raise an error. >> >>So I couldn'

Re: namespace dictionaries ok?

2005-10-25 Thread Duncan Booth
Ron Adam wrote: > James Stroud wrote: >> Here it goes with a little less overhead: >> >> > > But it's not a dictionary anymore so you can't use it in the same places > you would use a dictionary. > >foo(**n) > > Would raise an error. > > So I couldn't do: > > def foo(**kwds): >

Re: namespace dictionaries ok?

2005-10-25 Thread Steven D'Aprano
Simon Burton wrote: > Yes! > > I do this a lot when i have deeply nested function calls > a->b->c->d->e > and need to pass args to the deep function without changing the > middle functions. If you find yourself passing arguments to functions just so they can in turn pass them on to other fun

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
James Stroud wrote: > Here it goes with a little less overhead: > > > py> class namespace: > ... def __init__(self, adict): > ... self.__dict__.update(adict) > ... > py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) > py> n.bob > 1 > py> n.ted > 3 > > James How about... cl

Re: namespace dictionaries ok?

2005-10-24 Thread Ron Adam
James Stroud wrote: > Oops. Answered before I finished reading the question. > > James Well, the one bad side effect (or feature depending on the circumstance), is it makes a copy. I wonder if there is a way to modify the dictionary in place with a function to do the same thing instead of cre

Re: namespace dictionaries ok?

2005-10-24 Thread Bengt Richter
On Tue, 25 Oct 2005 03:10:17 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >Simon Burton wrote: > >> Yes! >> >> I do this a lot when i have deeply nested function calls >> a->b->c->d->e >> and need to pass args to the deep function without changing the >> middle functions. > >Yes, :-) Which is somet

Re: namespace dictionaries ok?

2005-10-24 Thread James Stroud
Oops. Answered before I finished reading the question. James On Monday 24 October 2005 19:53, Ron Adam wrote: > James Stroud wrote: > > Here it goes with a little less overhead: > > > > > > py> class namespace: > > ... def __init__(self, adict): > > ... self.__dict__.update(adict) > > ... >

Re: namespace dictionaries ok?

2005-10-24 Thread Ron Adam
Simon Burton wrote: > Yes! > > I do this a lot when i have deeply nested function calls > a->b->c->d->e > and need to pass args to the deep function without changing the > middle functions. Yes, :-) Which is something like what I'm doing also. Get the dictionary, modify it or validate it som

Re: namespace dictionaries ok?

2005-10-24 Thread Ron Adam
James Stroud wrote: > Here it goes with a little less overhead: > > > py> class namespace: > ... def __init__(self, adict): > ... self.__dict__.update(adict) > ... > py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) > py> n.bob > 1 > py> n.ted > 3 > > James But it's not a dictio

Re: namespace dictionaries ok?

2005-10-24 Thread Simon Burton
Yes! I do this a lot when i have deeply nested function calls a->b->c->d->e and need to pass args to the deep function without changing the middle functions. In this situation I think i would prefer this variation: class Context(dict): def __init__(self,**kwds): dict.__init__(self,kwds)

Re: namespace dictionaries ok?

2005-10-24 Thread James Stroud
Here it goes with a little less overhead: py> class namespace: ... def __init__(self, adict): ... self.__dict__.update(adict) ... py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) py> n.bob 1 py> n.ted 3 James On Monday 24 October 2005 19:06, Ron Adam wrote: > Hi, I found the fo

namespace dictionaries ok?

2005-10-24 Thread Ron Adam
Hi, I found the following to be a useful way to access arguments after they are passed to a function that collects them with **kwds. class namespace(dict): def __getattr__(self, name): return self.__getitem__(name) def __setattr__(self, name, value):