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


Groups > de.comp.lang.python > #5914

[Python-de] Klasse mit Class Variables in String umwandeln

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Marc Haber <mh+python-de@zugschlus.de>
Newsgroups de.comp.lang.python
Subject [Python-de] Klasse mit Class Variables in String umwandeln
Date Mon, 5 Dec 2022 21:33:02 +0100
Lines 53
Message-ID <Y45Vft05pyH3xkxq@torres.zugschlus.de> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de 7oon/XPjbHbthu4hFwjtcQRsXJ8igA/wU1CJI8LorDzg==
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
Content-Disposition inline
User-Agent Mutt/2.0.5 (2021-01-21)
Message-ID-Hash COIB3XO743MGL3HJQE2QITCLCT25B6HJ
X-Message-ID-Hash COIB3XO743MGL3HJQE2QITCLCT25B6HJ
X-MailFrom mh+python-de@zugschlus.de
X-Mailman-Rule-Misses dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-python-de.python.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Mailman-Version 3.3.7
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
Archived-At <https://mail.python.org/archives/list/python-de@python.org/message/COIB3XO743MGL3HJQE2QITCLCT25B6HJ/>
List-Archive <https://mail.python.org/archives/list/python-de@python.org/>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Owner <mailto:python-de-owner@python.org>
List-Post <mailto:python-de@python.org>
List-Subscribe <mailto:python-de-join@python.org>
List-Unsubscribe <mailto:python-de-leave@python.org>
Xref csiph.com de.comp.lang.python:5914

Show key headers only | View raw


Hallo,

wenn ich dieses Programm ausführe, tut es das was es soll:

#!/usr/bin/python


class Config1:↲
    classvar = None

    def __init__(self, value, clsvar):
       self.member = value
       Config1.classvar = clsvar

    def __repr__(self):
       retr = str(self.member)
       retr += " "
       retr += str(Config1.classvar)
       return retr


class Config:
    member = None


config1 = Config1("blubb", "classvar")
print(str(config1))

Config.member = "bla"
print(Config.member)


$ ./keks2.py 
blubb classvar
bla
$

Nur finde ich die Art, wie die Klasse Config1 selbst weiß, wie sie sie
selbst in einen String wandeln soll, sehr viel eleganter als in der
Klasse, die nur Klassenvariablen hat und niemals instanziiert wird. Wenn
sie niemals instanziiert wird, kann sie auch keine Methoden haben,
richtig?

Wie schreibe ich das "schöner" hin?

Grüße
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany    |  lose things."    Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature |  How to make an American Quilt | Fax: *49 6224 1600421

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

[Python-de] Klasse mit Class Variables in String umwandeln Marc Haber <mh+python-de@zugschlus.de> - 2022-12-05 21:33 +0100

csiph-web