Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197480
| From | Jonathan Gossage <jgossage@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Dynamic classes |
| Date | 2025-05-19 11:51 -0400 |
| Message-ID | <mailman.63.1747669953.3008.python-list@python.org> (permalink) |
| References | <CAApdmf3UwA6zf2-eSfd=1U=Unx3-6PUj6+XS0Sp62rkn73C8iQ@mail.gmail.com> |
I have created a dynamic class using the type() function:
x = type('MyFlags', (), {'Flag1': 1, 'Flag2': 2, 'Flag3: 4, ' '__init__' :
__init__})
The new class is there, and the class variables, Flag1, Flag2, and Flag3,
are present correctly. However, when I try to create an instance of this
class with the following code:
y = x('Flag1', 'Flag2')
it fails with a TypeError stating that 'MyFlags' does not accept arguments.
What do I have to do to make this happen?. BTW __init__(self, *args) is
defined as the instance initializer.
--
Jonathan Gossage
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
Dynamic classes Jonathan Gossage <jgossage@gmail.com> - 2025-05-19 11:51 -0400
Re: Dynamic classes ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-19 16:33 +0000
Re: Dynamic classes Greg Ewing <greg.ewing@canterbury.ac.nz> - 2025-05-20 12:29 +1200
csiph-web