I may be missing something, but isn't this what __dict__ does? Just
return self.__dict__. This is an old message, so this may have mentioned
already. Sorry if that's the case. I'm a little behind.
Kent Johnson wrote:
>Smith, Jeff wrote:
>
>
>>Here would be the usage:
>>
>>myinst = MyClass()
>
Smith, Jeff wrote:
> That's what I was looking for. Although I couldn't get the below to
> work, I went with a different mod of the original you gave:
>
> def get_props_as_dict(self):
> d = dict()
> for entry in dir(self.__class__):
> if isinstance(getattr(self.__c
, property):
d[entry] = getattr(self, entry)
return d
Thanks!
Jeff
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kent Johnson
Sent: Thursday, June 23, 2005 4:39 PM
To: Python Tutor
Subject: Re: [Tutor] Interesting problem
Smith,
> Consider a class with a lt of properties. I would like a member
> function which generates a dictionary where the keys are the
property
> names and the values are the property values?
Use the force... :-)
Since Python uses dictionaries to store all those things
already there must be a suitable
Smith, Jeff wrote:
> Here would be the usage:
>
> myinst = MyClass()
> print myinst.getprops_as_dict()
>
> would print
>
> {'var1': 1, 'var2': 2, 'var3': 3}
>
> Needless to say I want the instance values which might be different for
> each instance. I know that I could code it brute force, but
Of Kent Johnson
Sent: Thursday, June 23, 2005 3:17 PM
To: Python Tutor
Subject: Re: [Tutor] Interesting problem
Still not that clear. What do you want to see when you call
MyClass().getprops_as_dict() ?
Maybe this will give you some ideas:
>>> class MyClass:
... def __init__(self, val1
Smith, Jeff wrote:
> I can see I wasn't clear :-)
>
> Here's the basic framework of what I'm looking for. Needless to say,
> this is just an example and not the real problem which is quite
> complicated and includes multiple classes.
>
> What I'm looking for is the actual implementation of get_p
ilto:[EMAIL PROTECTED] On
Behalf Of Smith, Jeff
Sent: Thursday, June 23, 2005 2:01 PM
To: tutor@python.org
Subject: [Tutor] Interesting problem
Consider a class with a lt of properties. I would like a member
function which generates a dictionary where the keys are the property
names and the value
Smith, Jeff wrote:
> Consider a class with a lt of properties. I would like a member
> function which generates a dictionary where the keys are the property
> names and the values are the property values?
>
> Is this clear?
No, actually :-)
Do you want the properties of the class (which are typ
> -Original Message-
>
> Consider a class with a lt of properties. I would like a member
> function which generates a dictionary where the keys are the property
> names and the values are the property values?
>
> Is this clear?
I think so :-)
> How might I go about this?
I think yo
Smith, Jeff wrote:
>Consider a class with a lt of properties. I would like a member
>function which generates a dictionary where the keys are the property
>names and the values are the property values?
>
>Is this clear?
>
>How might I go about this?
>
>Jeff
>__
Consider a class with a lt of properties. I would like a member
function which generates a dictionary where the keys are the property
names and the values are the property values?
Is this clear?
How might I go about this?
Jeff
___
Tutor maillist - T
12 matches
Mail list logo