Thanos Tsouanas wrote:
I'm not sure what you're getting at, but have you tried this:
class A(object):
def __getitem__(self, ky):
return self.__dict__[ky]
for example:
>>> class A(object):
def __init__(self,a,b,c):
self.a = a
self.b = b
Thanos Tsouanas wrote:
> On Sun, Jul 24, 2005 at 02:14:15PM -0600, Steven Bethard wrote:
>
>>How about something like:
>> dict((name, getattr(obj, name)) for name in dir(obj))
>
> Pretty!!!
>
>>Looks like this will get instance attributes, class attributes and
>>properties just fine.
>
> B
On Sun, Jul 24, 2005 at 02:14:15PM -0600, Steven Bethard wrote:
>
> How about something like:
> dict((name, getattr(obj, name)) for name in dir(obj))
Pretty!!!
> Looks like this will get instance attributes, class attributes and
> properties just fine.
But not SQLObject's objects...
Any i
John Machin wrote:
> Dark Cowherd wrote:
>
>>> voiceless-ly'rs
>>
>>
>> What does this mean?? Just curious (googled that and ly'rs and didnt
>> find anything relevant)
s/ly'rs/ly y'rs/
> The voiceless part I understand to mean that Bruno is "shocked and
> stunned and not a little bit amazed" [1]
Dark Cowherd wrote:
>>voiceless-ly'rs
>
> What does this mean?? Just curious (googled that and ly'rs and didnt
> find anything relevant)
The voiceless part I understand to mean that Bruno is "shocked and
stunned and not a little bit amazed" [1] at Steven's masterstroke which
came out of the blu
> voiceless-ly'rs
What does this mean?? Just curious (googled that and ly'rs and didnt
find anything relevant)
--
Dark Cowherd
--
http://mail.python.org/mailman/listinfo/python-list
*Grandmaster* Steven Bethard a écrit :
>
> How about something like:
> dict((name, getattr(obj, name)) for name in dir(obj))
>
...
voiceless-ly'rs
--
http://mail.python.org/mailman/listinfo/python-list
Thanos Tsouanas wrote:
> Steven Bethard wrote:
>
>>Maybe I'm not understanding your problem, but have you looked at the
>>builtin "vars()"?
>
> I didn't know about it, but I knew about object.__dict__ which is, as I
> see equivalent with vars(object). But it doesn't do the job for me,
> since i
Steven D'Aprano a écrit :
> On Sun, 24 Jul 2005 12:07:02 +0300, Thanos Tsouanas wrote:
>>
>>>Thanos Tsouanas wrote:
>>>
(snip)
>>I didn't know about it, but I knew about object.__dict__ which is, as I
>>see equivalent with vars(object). But it doesn't do the job for me,
>>since it fails to grab al
Steven D'Aprano a écrit :
> On Sun, 24 Jul 2005 12:03:47 +0300, Thanos Tsouanas wrote:
>>
>>Please, tell me, how would you print it in my case?
>
> If I have understood you, you have some object like such:
>
> obj.foo = 1
> obj.bar = 2
> obj.spam = 'a'
> obj.eggs = 'b'
>
> say.
>
> You want to
On Sun, 24 Jul 2005 12:07:02 +0300, Thanos Tsouanas wrote:
> On Sat, Jul 23, 2005 at 06:59:43PM -0600, Steven Bethard wrote:
>> Thanos Tsouanas wrote:
>> > I would like to have a quick way to create dicts from object, so that a
>> > call to foo['bar'] would return obj.bar.
>> >
>> > The following
On Sun, 24 Jul 2005 12:03:47 +0300, Thanos Tsouanas wrote:
> On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
>> On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
>> >
>> > print foo %do
>> >
>> > where do is a dictobj object...
>>
>> Are you telling me that the ONLY th
On Sun, Jul 24, 2005 at 03:01:40PM +0200, Bruno Desthuilliers wrote:
> I gave you a solution based on the Decorator pattern in another post,
> but there is also the possibility to add a __getitem__ method directly
> to the to-be-formatted object's class:
>
> def mygetitem(obj, name):
>return
Thanos Tsouanas a écrit :
>>On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
>>
>>>Hello.
>>>
>>>I would like to have a quick way to create dicts from object, so that a
>>>call to foo['bar'] would return obj.bar.
>>
(snip)
> print foo %do
>
> where do is a dictobj object...
I gave you
Steven D'Aprano a écrit :
> On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
>
>
(snip)
>
> Are you telling me that the ONLY thing you use dictobj objects for is to
> print them?
>
> I don't think so. I do know how to print an object, amazingly.
>
> Perhaps you would like to explain
Bruno Desthuilliers a écrit :
(snip)
> class Wrapper(object):
> def __init__(self, obj):
> self._obj = obj
> def __getitem__(self, name):
> return getattr(self._obj, name)
If you want the Wrapper to be more like a Decorator (ie still can use
the Wrapper object as if it was
On Sun, Jul 24, 2005 at 02:01:30PM +0200, Bruno Desthuilliers wrote:
> Thanos Tsouanas a écrit :
> > On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
> >
> > Because *obviously* I don't know of these indexing and attribute
> > grabbing machineries you are talking about in my case.
Thanos Tsouanas a écrit :
> On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
(snip)
>
>>Why jump through all those hoops to get attributes when Python already
>>provides indexing and attribute grabbing machinery that work well? Why do
>>you bother to subclass dict, only to mangle
On Sat, Jul 23, 2005 at 06:59:43PM -0600, Steven Bethard wrote:
> Thanos Tsouanas wrote:
> > I would like to have a quick way to create dicts from object, so that a
> > call to foo['bar'] would return obj.bar.
> >
> > The following works, but I would prefer to use a built-in way if one
> > exists.
On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
> On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
> >
> > print foo %do
> >
> > where do is a dictobj object...
>
> Are you telling me that the ONLY thing you use dictobj objects for is to
> print them?
I'm sorry to dis
On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
> On Sat, Jul 23, 2005 at 11:22:21PM +1000, Steven D'Aprano wrote:
>> On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
>> > Hello.
>> >
>> > I would like to have a quick way to create dicts from object, so that a
>> > call to fo
On Sat, 23 Jul 2005 13:50:36 -0400, Mike Meyer wrote:
>> I don't think this is particularly useful behaviour. How do you use it?
>
> def __str__(self):
> return self._format % self
That doesn't work. It calls self.__str__ recursively until Python halts
the process.
>>> class Thing(d
Thanos Tsouanas wrote:
> I would like to have a quick way to create dicts from object, so that a
> call to foo['bar'] would return obj.bar.
>
> The following works, but I would prefer to use a built-in way if one
> exists. Is there one?
Maybe I'm not understanding your problem, but have you look
On Sat, Jul 23, 2005 at 11:22:21PM +1000, Steven D'Aprano wrote:
> On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
> > Hello.
> >
> > I would like to have a quick way to create dicts from object, so that a
> > call to foo['bar'] would return obj.bar.
>
> That looks rather confusing to
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
>> Hello.
>>
>> I would like to have a quick way to create dicts from object, so that a
>> call to foo['bar'] would return obj.bar.
>
> That looks rather confusing to me. Why not just call obj.
On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
> Hello.
>
> I would like to have a quick way to create dicts from object, so that a
> call to foo['bar'] would return obj.bar.
That looks rather confusing to me. Why not just call obj.bar, since it
doesn't look like you are actually usi
Thanos Tsouanas a écrit :
> On Sat, Jul 23, 2005 at 12:06:57PM +0200, Paolino wrote:
>
>>use getattr(self.obj,key) possibly, as __getattribute__ gets total
>>control on attribute access
>
>
> Thanks, but what do you mean by 'total control'?
__getattribute__ is really some kind of an evil blac
Thanos Tsouanas wrote:
> On Sat, Jul 23, 2005 at 12:06:57PM +0200, Paolino wrote:
>
>>use getattr(self.obj,key) possibly, as __getattribute__ gets total
>>control on attribute access
>
>
> Thanks, but what do you mean by 'total control'?
>
Probably nothing to do with your question :(
But:
>>>
On Sat, Jul 23, 2005 at 11:30:19AM +0200, Bruno Desthuilliers wrote:
> Thanos Tsouanas a écrit :
> > class dictobj(dict):
> > """
> > class dictobj(dict):
> > A dictionary d with an object attached to it,
> > which treats d['foo'] as d.obj.foo.
> > """
> > def __init__(self,
On Sat, Jul 23, 2005 at 12:06:57PM +0200, Paolino wrote:
> use getattr(self.obj,key) possibly, as __getattribute__ gets total
> control on attribute access
Thanks, but what do you mean by 'total control'?
--
Thanos Tsouanas .: My Music: http://www.thanostsouanas.com/
http://thanos.sian
Thanos Tsouanas wrote:
> Hello.
>
> I would like to have a quick way to create dicts from object, so that a
> call to foo['bar'] would return obj.bar.
>
> The following works, but I would prefer to use a built-in way if one
> exists. Is there one?
>
> class dictobj(dict):
> """
> class
Thanos Tsouanas a écrit :
> Hello.
>
> I would like to have a quick way to create dicts from object, so that a
> call to foo['bar'] would return obj.bar.
>
> The following works, but I would prefer to use a built-in way if one
> exists. Is there one?
>
> Thanks in advance.
>
> class dictobj(di
Hello.
I would like to have a quick way to create dicts from object, so that a
call to foo['bar'] would return obj.bar.
The following works, but I would prefer to use a built-in way if one
exists. Is there one?
Thanks in advance.
class dictobj(dict):
"""
class dictobj(dict):
A dict
33 matches
Mail list logo