Getting a dictionary from an object
thanos at sians.org
Sun Jul 24 11:07:02 CEST 2005
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. Is there one?
> 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 it fails to grab all obj.foo's, some of them being properties,
vars() is good to know though, Thanks!
Thanos Tsouanas .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
More information about the Python-list