Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197480

Dynamic classes

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Jonathan Gossage <jgossage@gmail.com>
Newsgroups comp.lang.python
Subject Dynamic classes
Date Mon, 19 May 2025 11:51:53 -0400
Lines 14
Message-ID <mailman.63.1747669953.3008.python-list@python.org> (permalink)
References <CAApdmf3UwA6zf2-eSfd=1U=Unx3-6PUj6+XS0Sp62rkn73C8iQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace news.uni-berlin.de 8M1yiKecjuNHhEgqd0+dCQoA3+8A7FW8X/9msSNoKaJw==
Cancel-Lock sha1:EKw3/UTHiW9z4KVlzun+f3/MWXE= sha256:/kZOfdzseHcm3B9qkMx6DZE/N4M9DK27t2NJX/BWQW4=
Return-Path <jgossage@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
Authentication-Results mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=am5VF6kA; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status OK 0.183
X-Spam-Level *
X-Spam-Evidence '*H*': 0.66; '*S*': 0.02; 'fails': 0.09; 'instance': 0.16; 'variables,': 0.16; 'to:addr:python-list': 0.20; 'skip:_ 10': 0.22; 'present': 0.30; 'message-id:@mail.gmail.com': 0.31; 'subject:Dynamic': 0.32; 'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'following': 0.35; 'using': 0.37; 'class': 0.37; '8bit%:14': 0.38; 'try': 0.40; 'skip:i 20': 0.62; '8bit%:9': 0.64; 'accept': 0.67; 'btw': 0.84; 'stating': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747669950; x=1748274750; darn=python.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Cj6csy2qL4wNhw21kJLpN6d5qLQlvTVhtm8GQ3uBuMY=; b=am5VF6kATnII8qAF3kK/o0VFElUl1d1yOfpac5tSWcFTnaInQU8fsliADAYJLooooQ o4FCg3e0bDmPNX8oQ/LUhaSPcbWvBfQn/DzlYn4vrhiDjMFPIBGpuEwSWxhcnuyV8tVl 3iFYw0MLoyrL4qrkaM29lguSz8dQa4hDITcERiGUKySGuaJgriS7BhwGwjwPGRmmbZXk znQmcFPBbINyLnvRBw+x/T7mO+9O2VWEKJBdQGRo6xEJjKd4q3sTUGDpl5tGbsZuPfO4 RzeYjFUCXxyX6vyIOhLzNkuJGUUDpTItGvUMI2DjfZosqlOzWQvzjn49s+2TlyAkIi/U TS4w==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747669950; x=1748274750; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Cj6csy2qL4wNhw21kJLpN6d5qLQlvTVhtm8GQ3uBuMY=; b=WOBJCRbB+rbRmAM7tTcTyrQ9DTiNoBDzb97ZgBcBvFDgYiIMf/jMf+VDIcCaBJ9wkI HmRE94Dq4k3C98TNIaRyt4Q3K7MeG8XEciNn9knmM9VM5QMhqfD8iPBtMSGfgVCvcjTT 3jiEIcpBjyltT63t/bedkAg6kWriyw5lmUUVxdiUib4VSSc4FWSA5Y8COcNsG8uyV4WC Dvzy9lwnqpwJaN0ZPvlu6rUWKw94jDeqcMfefSLKjVEV9Fv8R0by6pE2GwSf4oIVctlQ uFObwQyHNjFHx4aneD4fae7SJr6STg6jkFlaFW20zXHdPu2oFm/a9DxMgV1nBOtNGZJ3 ZfSg==
X-Gm-Message-State AOJu0Yz+elcaeGu3ym0vnL7njLIDLO6BtBgXPKM1AF291VDfitbg+BOF J++LaHb/PBQ35B7NYE14X9zU7+n71VC1rRhwKHyUsi/+vS/xN+JcFSznd7SRQwkd5y7wVDTJYF7 qwusFrRRBMvw8RQdCdkuhPC7ljJS3cB2k0mC+eYk=
X-Gm-Gg ASbGncv1QkRBo5geQADRV+5mD6k9Ymwi+3yVzqyWwsdv4/3bs+4zeAAEIVl2VgFkiMi RvAjERxS0hmhee16eYYXWjqxxZKhUPDwEECNspgQ645g+KGIFzJfrHYkMQgb84Q6XHGpoJqyWLS Ef1osKw3s3olXPTOh4tCHQ15C2kpvmUJuCSIw=
X-Google-Smtp-Source AGHT+IFdN4HrWPm4qkJpfSjP9YLdM03MPW7JwlF7JMu1SXLgag7YBm0QhcinvGzRU0fWSg/NnLPO9HHsaBIS5OumTtU=
X-Received by 2002:a17:902:db07:b0:224:1001:677c with SMTP id d9443c01a7336-231de351468mr173559265ad.9.1747669950173; Mon, 19 May 2025 08:52:30 -0700 (PDT)
X-Gm-Features AX0GCFuTC-AI3opLHkfidR3Lq-L9REVISKjIF82qlvfK67GkNquW61No-AtToKI
X-Content-Filtered-By Mailman/MimeDel 2.1.39
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.39
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <https://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAApdmf3UwA6zf2-eSfd=1U=Unx3-6PUj6+XS0Sp62rkn73C8iQ@mail.gmail.com>
Xref csiph.com comp.lang.python:197480

Show key headers only | View raw


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 | NextNext in thread | Find similar


Thread

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