List of Functions
Chris Angelico
rosuav at gmail.com
Mon Mar 28 19:40:18 EDT 2016
On Tue, Mar 29, 2016 at 9:52 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> That would be called "type" :-)
>
> type(name, bases, namespace) returns a new class:
>
>
> py> C = type("MyClass", (object,), {'foo': 1})
> py> C
> <class '__main__.MyClass'>
> py> C.foo
> 1
Yeah, but to do that in a single expression, you need to have all the
functions in the dictionary, so it's no improvement over
SimpleNamespace. The functions get attached to the class, not the
instance, which means they need 'self' - but without assignment, you
wouldn't be able to make much use of self anyway. Hence the call for
an example.
ChrisA
More information about the Python-list
mailing list