December 2000
Intermediate to advanced
816 pages
16h 57m
English
What is an attribute? An attribute is a data or functional element which belongs to another object and is accessed via the familiar dotted-attribute notation. Some Python types such as complex numbers have data attributes (real and imag), while others such as lists and dictionaries have methods (functional attributes).
One interesting side note about attributes is that when you are accessing an attribute, it is also an object and may have attributes of its own which you can then access, leading to a chain of attributes, i.e., myThing.subThing.subSubThing, etc. Some familiar examples are:
• sys.stdout.write('foo')
• print myModule.myClass.__doc__
• myList.extend(map(upper, open('x').readlines()))
Class attributes are ...
Read now
Unlock full access