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.__class__, entry), property):
>                 d[entry] = getattr(self, entry)
>         return d
> 

OK good! My code was untested and requires Python 2.4. I'm glad you could turn 
it into something that works for you.

Kent
> Thanks!
> Jeff
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Kent Johnson
> OK, so will a variation on my last recipe work? This looks for property
> attributes of the class and gets the corresponding property on the
> instance:
>   def getprops_as_dict(self):
>     return dict(pname, getattr(self, pname) 
>       for pname in dir(self.__class__) 
>         if isinstance(getattr(self.__class__, pname), property))
>     )
> 
> Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to