Re: [Tutor] Interesting problem

2005-06-28 Thread Chuck Allison
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() >

Re: [Tutor] Interesting problem

2005-06-23 Thread Kent Johnson
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Smith, Jeff
, 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,

Re: [Tutor] Interesting problem

2005-06-23 Thread Alan G
> 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

Re: [Tutor] Interesting problem

2005-06-23 Thread Kent Johnson
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Smith, Jeff
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Kent Johnson
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Smith, Jeff
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Kent Johnson
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

Re: [Tutor] Interesting problem

2005-06-23 Thread Christian Wyglendowski
> -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

Re: [Tutor] Interesting problem

2005-06-23 Thread Jeremy Jones
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 >__

[Tutor] Interesting problem

2005-06-23 Thread Smith, 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