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


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

Re: [Python-de] "property-init"-decorator

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Julian Gethmann <mail.python.org@gethmann.org>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] "property-init"-decorator
Date Tue, 26 May 2020 18:07:26 +0200
Lines 53
Message-ID <mailman.131.1590509258.27263.python-de@python.org> (permalink)
References <875zci8zut.fsf@orrococo> <7d63d378-eae2-c670-85cf-b8e05988e539@gethmann.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de 6X6xS8ur/P4zA1UgrBCe7AXPaVr3pKuU7vPanow8pXKA==
Return-Path <mail.python.org@gethmann.org>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0
In-Reply-To <875zci8zut.fsf@orrococo>
Content-Language en-US
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.33
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <7d63d378-eae2-c670-85cf-b8e05988e539@gethmann.org>
X-Mailman-Original-References <875zci8zut.fsf@orrococo>
Xref csiph.com de.comp.lang.python:5635

Show key headers only | View raw


Hallo Ole,

leider habe ich selbst auch noch keine Erfahrung mit der Bibliothek 
gemacht und ich bin mir auch nicht sicher, ob sie deinen Fall abdeckt, 
aber kennst du pydantic?
https://pydantic-docs.helpmanual.io/usage/validators/

Falls deine Klasse nur ein Datenkontainer ist, könnte ich mir gut 
vorstellen, dass die Bibliothek das macht, was du willst, falls der 
Aspekt nur ein kleiner Aspekt ist, ist pydantic vllt. doch nichts für dich.

Viele Grüße,
Julian

On 26/05/2020 17:44, Оlе Ѕtrеісhеr wrote:
> Hallo,
> 
> wir möchten in einer Klasse eine Reihe von Attributen konsistent
> speichern; d.h. es gibt Beschränkungen für die verschiedenen Attribute.
> Die Idee ist, das durch Properties zu machen:
> 
> Class Cfg:
>      def __init__(self);
>          self._myprop = 1.23
> 
>      [...]
> 
>      @property
>      def myprop(self)
>          return self._myprop
> 
>      @myprop.setter
>      def myprop(self, val):
>          if val > self._maxprop: # als Beispiel
>              raise ValueError()
>          self._myprop = val
> 
> 
> Das Unschöne daran ist, dass die Initialisierung der Property im
> __init__ und damit physisch weit entfernt vom Rest erfolgt. Das ist,
> wenn man viele (>>20) Attribute hat, nicht mehr übersichtlich.
> 
> Wie bringt man die enger zusammen? Ein @myprop.init gibt es ja
> offensichtlich nicht und kann man auch nicht so ohne weiteres anlegen,
> oder? Oder was wäre ein sinnvolles Pattern hier?
> 
> Schöne Grüße
> 
> Ole
> _______________________________________________
> python-de maillist  -  python-de@python.org
> https://mail.python.org/mailman/listinfo/python-de
> 

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


Thread

"property-init"-decorator ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2020-05-26 17:44 +0200
  Re: [Python-de] "property-init"-decorator Julian Gethmann <mail.python.org@gethmann.org> - 2020-05-26 18:07 +0200
  Re: [Python-de] "property-init"-decorator Hartmut Goebel <h.goebel@goebel-consult.de> - 2020-05-27 10:27 +0200
  Re: "property-init"-decorator "Andreas B." <ab@sysing.de> - 2020-05-27 13:18 +0200
  Re: [Python-de] "property-init"-decorator Gregor Engberding <gregor@landit.de> - 2020-05-27 17:04 +0200
  Re: [Python-de] "property-init"-decorator Peter Otten <__peter__@web.de> - 2020-05-27 17:13 +0200
  Re: [Python-de] "property-init"-decorator Hartmut Goebel <h.goebel@goebel-consult.de> - 2020-05-31 10:13 +0200
  Re: [Python-de] "property-init"-decorator Peter Otten <__peter__@web.de> - 2020-05-31 15:37 +0200

csiph-web