python-__shots__

1. Assign string attribute names to special __shots__ class attributes in sequence, and new-style classes may not only limit the legal attributes that instances of the class will have, but also optimize memory and speed performance

2.eg:

   class limiter:

            __shots__ = ['age','name,'job'']

x = limit()

x.age() # will report an error AttributeError:age

x.age = 40

x.age #output result 40

x.ape = 1000# will report an error, there is no such variable, if it is in a class without __shots__, this statement will create a new variable

3. A class with __shots__ usually has no attribute dictionary for its instances

That is, x.__dict__ will report an error

4.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325939018&siteId=291194637