[Baypiggies] The correct / consistent way to work with class attributes

Martin Falatic martin at falatic.com
Sat Jul 26 05:35:20 CEST 2014


Well, when I went poking around for it I stumbled on type(self) first and
thought that was the done thing, but that was apparently a blind alley for
this purpose. I like self.__class__ more than the explicit class name so
I'm keep that in mind when I need to do that. :-)

I didn't like either answer on S.O.... neither suggested (as one commenter
did) the use of self.__class__, which is pretty much what I was looking
for.

Thanks again!

 - Marty


On Fri, July 25, 2014 19:06, wesley chun wrote:
> I prefer self.__class__.attribute the most, followed by using the class
> name.

On Fri, July 25, 2014 17:12, Shannon -jj Behrens wrote:
> Is there any case that using self.__class__.attribute doesn't address?
>


>
> On Fri, Jul 25, 2014 at 11:14 AM, Martin Falatic <martin at falatic.com>
> wrote:
>
>
>> My question on Stack Overflow is getting a lot of traffic but little
>> love:
>> http://stackoverflow.com/questions/24923749/
>>
>>
>> Perhaps the more exact question after all that discussion is, what's
>> the best (Pythonic and consistent) way to work with class attributes
>> from within a given (new-style) class? type(self), self.__class__, the
>> explicit class name, something else?
>>
>> It seems to me that putting the explicit class name into a class is
>> redundant, and I was told meta-classes can cause issues with using
>> type() when considering how Python 2.7 works versus 3.4 (I'm not as well
>> versed on meta-classes yet so I'm not sure what the specific difference
>> is supposed to be there - but I'd like to understand it).
>>
>> Thoughts?
>>
>>
>> - Marty
>>
>>
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> https://mail.python.org/mailman/listinfo/baypiggies
>>
>>
>
>
>
> --
> In this life we cannot do great things. We can only do small things with
> great love. -- Mother Teresa
>




More information about the Baypiggies mailing list