>>> class CObj (object):
... pass
...
>>> dir ()
['cobj', ' __builtins__ ', ' __doc__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __spec__ ']
>>> COB = CObj
>>> dir ()
[' CObj ', ' __builtins__ ', ' __doc__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __spec__ ', 'cob']
>>> Help (__name__)
Help on module __main__:
NAME
__main__
CLASSES
Builtins.object
CObj
Class CObj (Builtins.object)
| Data descriptors defined here:
|
| __dict__
| Dictionary for instance variables (if defined)
|
| __weakref__
| List of weak references to the object (if defined)
COB = Class CObj (builtins.object)
| Data descriptors defined here:
|
| __dict__
| Dictionary for instance variables (if defined)
|
| __weakref__
| List of weak references to the object (if defined)
FILE
(built-in)
>>> cins = COB ()
>>> Cins
<__main__. CObj object at 0x0000000000b5cc88>
>>> cins2 = CObj ()
>>> Cins2
<__main__. CObj object at 0x00000000013f5e10>
>>> cobj.x1 = 20
>>> Cins
<__main__. CObj object at 0x0000000000b5cc88>
>>> cins.x1
20
>>> cins2.x1
20
>>> cins2.y1=30
>>> cins.y1
Traceback (most recent):
File "<stdin>", line 1, in <module>
Attributeerror: ' CObj ' object has no attribute ' y1 '
>>> cobj.y1
Traceback (most recent):
File "<stdin>", line 1, in <module>
Attributeerror:type object ' CObj ' has no attribute ' y1 '
>>> dir (cins)
[' __class__ ', ' __delattr__ ', ' __dict__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' _ _
Gt__ ', ' __hash__ ', ' __init__ ', ' __le__ ', ' __lt__ ', ' __module__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __
Repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' __weakref__ ', ' x1 '
>>> dir (cins2)
[' __class__ ', ' __delattr__ ', ' __dict__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' _ _
Gt__ ', ' __hash__ ', ' __init__ ', ' __le__ ', ' __lt__ ', ' __module__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __
Repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' __weakref__ ', ' x1 ', ' y1 '
>>> dir (COB)
[' __class__ ', ' __delattr__ ', ' __dict__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' _ _
Gt__ ', ' __hash__ ', ' __init__ ', ' __le__ ', ' __lt__ ', ' __module__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __
Repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' __weakref__ ', ' x1 '
>>> dir (cobj)
[' __class__ ', ' __delattr__ ', ' __dict__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' _ _
Gt__ ', ' __hash__ ', ' __init__ ', ' __le__ ', ' __lt__ ', ' __module__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __
Repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' __weakref__ ', ' x1 '
>>>
>>> hasattr (CObj, X1)
Traceback (most recent):
File "<stdin>", line 1, in <module>
Nameerror:name ' x1 ' is not defined
>>> hasattr (cobj, ' X1 ')
True
>>> hasattr (cobj, ' Y1 ')
False
>>> hasattr (cobj, ' Y1 ')
Python class Metaclass instance