Metaclass Question
Jay Parlar
jparlar at cogeco.ca
Wed Oct 6 22:50:32 EDT 2004
More information about the Python-list mailing list
Wed Oct 6 22:50:32 EDT 2004
- Previous message (by thread): Metaclass Question
- Next message (by thread): Metaclass Question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Oct 6, 2004, at 7:23 PM, CarThe answer is *simple*. In fact, it's embarassingly simple. Do it > inside a loop. Really. > > for i in range(10): > def newfunc(...): > ... > > ... will create as many copies of newfunc as you want; it will bind > all to the same name in the local namespace, but each and every > instance will be different. The func_name attribute will be 'newfunc' > for all functions created, though; but if you're using 2.4, you can > rename them later, by changing the func_name attribute, that is now > writable. > But in the example I posted, new_func already is in a loop (for func_name in funcs) On the surface, it looks like it works. The keys in cls.nameReg[name] show different references for the new_funcs, but when they're actually called, they all run with the same values. Jay P. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2363 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20041006/1b522dd9/attachment.bin>
- Previous message (by thread): Metaclass Question
- Next message (by thread): Metaclass Question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list