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
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
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
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
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'
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
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
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
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
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,
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
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
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
> 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
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
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
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'
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):
>
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
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
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
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
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)
> > ...
>
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
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
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)
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
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):
28 matches
Mail list logo