Created
June 1, 2020 14:00
-
-
Save eclecticmiraclecat/b8a9fb74765c16243210e3a34c747dbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Foo(object): | |
... def __init__(self, x): | |
... self.x = x | |
... def spam(self): | |
... print('spam') | |
... | |
>>> f = Foo(2) | |
>>> f.x | |
2 | |
>>> f.spam() | |
spam | |
>>> | |
>>> name = 'Foo' | |
>>> bases = (object, ) | |
>>> def __init__(self, x): | |
... self.x = x | |
... | |
>>> def spam(self): | |
... print('spam') | |
... | |
>>> methods = {'__init__': __init__, 'spam': spam} | |
>>> | |
>>> name | |
'Foo' | |
>>> bases | |
(<class 'object'>,) | |
>>> methods | |
{'__init__': <function __init__ at 0x7f95b61b0598>, 'spam': <function spam at 0x7f95b61b0730>} | |
>>> Foo = type(name, bases, methods) | |
>>> Foo | |
<class '__main__.Foo'> | |
>>> f = Foo(2) | |
>>> f.x | |
2 | |
>>> f.spam() | |
spam |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment