Dynamic classes

Liste des GroupesRevenir à cl python 
Sujet : Dynamic classes
De : jgossage (at) *nospam* gmail.com (Jonathan Gossage)
Groupes : comp.lang.python
Date : 19. May 2025, 16:51:53
Autres entêtes
Message-ID : <mailman.63.1747669953.3008.python-list@python.org>
References : 1
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

Date Sujet#  Auteur
19 May 25 * Dynamic classes3Jonathan Gossage
19 May 25 `* Re: Dynamic classes2Stefan Ram
20 May 25  `- Re: Dynamic classes1Greg Ewing

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal