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


Groups > comp.lang.python > #197487

Re: Dynamic classes

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups comp.lang.python
Subject Re: Dynamic classes
Date 21 May 2025 11:20:55 GMT
Organization Stefan Ram
Lines 70
Expires 1 Jun 2026 11:59:58 GMT
Message-ID <dynamic-20250521121804@ram.dialup.fu-berlin.de> (permalink)
References <mailman.67.1747767982.3008.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de cA4E7/zNXwSsVIl3g4dNWA40BxVwxY/GqjIBOM/7RaX7Hw
Cancel-Lock sha1:uKESxVl+dDHVLBKWjghVJlvOLlU= sha256:NLMfBZsQLWWackaXH3I0dfJpoLVkIESxbxr25N2u07w=
X-Copyright (C) Copyright 2025 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed.
X-No-Archive Yes
Archive no
X-No-Archive-Readme "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access.
X-No-Html yes
Content-Language en-US
Xref csiph.com comp.lang.python:197487

Show key headers only | View raw


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


Thread

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