[Tutor] Good approach regarding classes attributes

Sydney Shall s.shall at virginmedia.com
Tue Sep 9 16:02:01 CEST 2014


On 09/09/2014 15:44, Peter Otten wrote:
> Sydney Shall wrote:
>
>> On 08/09/2014 18:39, Alan Gauld wrote:
>>> On 08/09/14 15:17, Juan Christian wrote:
>>>
>>> One tiny tweak...
>>>
>>>> class User():
>>> You don't need the parens after User. You don;t have any superclasses
>>> so they do nothing. Python convention for an empty parent list is just
>>> to leave the parens off:
>>>
>>> class User:
>>>
>> A simple question from a newbie, in response to this surprise.
>> Is it not helpful to always put (object) as the parent, if the class is
>> not itself a sub-class?
> The answer differs between Python 2 and 3. In Python 3
>
> class C: # preferred in Python 3
>      pass
>
> and
>
> class C(object):
>      pass
>
> are the same, so there is no point adding the explicit object inheritance.
>
> In Python 2 however
>
> class C:
>      pass
>
> will create a "classic class" whereas
>
> class C(object): # preferred in Python 2
>      pass
>
> is a "newstyle class". The most notable difference between these is that
> properties work correctly only with newstyle classes. Therefore making all
> your classes "newstyle" is a good idea.
>
>> And while I am writing, what does OP stand for in this list?
> Original Poster, as Leam says.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
Thanks Peter, most helpful.
I was taught with Python 2.7, so  now I understand the advice.


-- 
Sydney Shall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140909/502cb8e0/attachment-0001.html>


More information about the Tutor mailing list