Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197487
| From | ram@zedat.fu-berlin.de (Stefan Ram) |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Dynamic classes |
| Date | 2025-05-21 11:20 +0000 |
| Organization | Stefan Ram |
| Message-ID | <dynamic-20250521121804@ram.dialup.fu-berlin.de> (permalink) |
| References | <mailman.67.1747767982.3008.python-list@python.org> |
Left Right <olegsivokon@gmail.com> wrote or quoted:
>I find that it's generally more convenient to do this using similar code:
>def constructor(flag1, flag2):
> class _Hidden:
That tracks, but I have this setup where I lay out a table to
map out my markup language [1] and then use some dynamic code
to spin up the classes based on that table [0], and I am not
really sure how your way would fit in with that.
[0]
globals_dict = globals()
for name, props in element_properties.items():
cls = type(name.capitalize(), (Element,), {'element_properties': props})
globals_dict[name.capitalize()] = cls
[1]
element_properties = {
'title': {
'level': IS_BLOCK,
'contents': CANT_CONTAIN_ELEMENTS,
'open_tag': None,
'close_tag': None,
'use_check': False,
},
'author': {
'level': IS_BLOCK,
'contents': CANT_CONTAIN_ELEMENTS,
'open_tag': None,
'close_tag': None,
'use_check': False,
},
'language': {
'level': IS_BLOCK,
'contents': CANT_CONTAIN_ELEMENTS,
'open_tag': None,
'close_tag': None,
'use_check': False,
},
'h1': {
'level': IS_BLOCK,
'contents': CAN_CONTAIN_ELEMENTS,
'open_tag': '<h1>',
'close_tag': '</h1>',
'use_check': True,
},
'toc': {
'level': IS_BLOCK,
'contents': CANT_CONTAIN_ELEMENTS,
'open_tag': None,
'close_tag': None,
'use_check': False,
},
'head': {
'level': IS_BLOCK,
'contents': CANT_CONTAIN_ELEMENTS,
'open_tag': None,
'close_tag': None,
'use_check': False,
},
'par': {
'level': IS_BLOCK,
. . .
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Dynamic classes Left Right <olegsivokon@gmail.com> - 2025-05-20 08:03 +0200
Re: Dynamic classes ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-21 11:20 +0000
Re: Dynamic classes (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-22 00:19 +0000
csiph-web