Python is a very flexible language, and it can be seen in light of the access mechanism of the properties between its classes and instances, but this is really not a good idea, and after doing some tests, I understand that:
When the instance accesses the Class property, first retrieves its own names, if has the words to take out directly, does not have the words to come to the names inside to look for, cannot find is the error
classPclass (object):"""docstring for Pclass"""Num= 10def __init__(self): Super (Pclass, self).__init__() P=Pclass ()Print(P.num)#TenP.num = p.num + 1Print(P.num)# OnePrint(Pclass.num)#TenPclass.age=12Print(Pclass.age)# APrint(P.age)# Ap.xxx=555Print(P.XXX)#555Print(PCLASS.XXX)#Attributeerror:type object ' Pclass ' has no attribute ' xxx '
Python-04182016-Understanding of attributes between classes and instances