Files
Mastering-Python-2e-code_2/CH_08_metaclasses/T_00_dynamically_creating_classes.rst
T
2022-05-05 18:25:55 +02:00

28 lines
507 B
ReStructuredText

>>> class Spam(object):
... eggs = 'my eggs'
>>> Spam = type('Spam', (object,), dict(eggs='my eggs'))
------------------------------------------------------------------------------
>>> class Spam(object):
... eggs = 'my eggs'
>>> spam = Spam()
>>> spam.eggs
'my eggs'
>>> type(spam)
<class '...Spam'>
>>> type(Spam)
<class 'type'>
>>> Spam = type('Spam', (object,), dict(eggs='my eggs'))
>>> spam = Spam()
>>> spam.eggs
'my eggs'
>>> type(spam)
<class '...Spam'>
>>> type(Spam)
<class 'type'>