Getting a dictionary from an object
steve at REMOVETHIScyber.com.au
Sun Jul 24 05:43:43 CEST 2005
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 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 using the dictionary at all?
>> > [...]
>> I don't think this is particularly useful behaviour. How do you use it?
> print foo %do
> where do is a dictobj object...
Are you telling me that the ONLY thing you use dictobj objects for is to
I don't think so. I do know how to print an object, amazingly.
Perhaps you would like to explain how you use the rest of the
functionality of the dictobj, instead of taking my words out of context
and giving an inane answer.
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 the dict __getitem__ method so
that you can no longer retrieve items from the dict?
More information about the Python-list