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


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

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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Gregor Engberding <gregor@landit.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] "property-init"-decorator
Date Wed, 27 May 2020 17:04:00 +0200
Lines 58
Message-ID <mailman.154.1590592310.27263.python-de@python.org> (permalink)
References <875zci8zut.fsf@orrococo> <e89df817-e4b7-20b3-03f7-c32635f5f769@landit.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de 1X9ICdLWKfEW4jzbBog0zgCxZwhQnHjxS30rBY9oCm0g==
Return-Path <gregor@landit.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
Authentication-Results mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=landit.de header.i=@landit.de header.b=JI2pI6cQ; dkim-adsp=pass; dkim-atps=neutral
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=landit.de; s=2017; t=1590591843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XcgXMeHRycUZ3r361R9+giEBl1YIZFMDea5erFttQt4=; b=JI2pI6cQstWak1s+DMqCbgE2BwxPEhjFZ9w7b93DQKmc8gKM0fFwGMaubW/V7Ck/z73Vso cPEQ0lF9K90C28x1x8t7SmpwVe8irCU7ch+7hMK5qpLhssO3QIUf7Dglk+NmImfiut05yS CmPvqb6xpLCDU4CVjaKSPoC1tyjHDt2l+XVeu5NKFvUlcXY2ed+1oXmcJXrG39bGaeM/ht T2sXNVSnkpkeLHOKy6TlhsgCDEZoZk6maIxxlxp1/Q4T2hAxXdBm7RhGnhOMyuIc41PEae Sn6RbZmwUIHke5HhdzxO3H73reicMc56PHNnu+jdaBp/63GtRolYuYbfq44XRQ==
In-Reply-To <875zci8zut.fsf@orrococo>
Content-Language de-DE
ARC-Message-Signature i=1; a=rsa-sha256; c=relaxed/relaxed; d=landit.de; s=2017; t=1590591843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XcgXMeHRycUZ3r361R9+giEBl1YIZFMDea5erFttQt4=; b=hYgjEQkrEl/j65thghrYZYAzEBbKvVZvjLs+zxOSdV8LjpKtEYkI3ecnt4DW5YDVxayCbc nezxqHR97PDDcjou+Ya9VsIz6IoYybS63VnXq+T9Kj1MR0II3H8G2Xp2dRD5sBWi+5ruue SHWNkuUITtMDaaotX9R9vetFKXv4WgixQD9fsSikvs3HMeQDdmDx6LhTbnDKHcUHbUq1CT Sd0xdM6fu/svcuYHOLMRPY057IDgB4MP6vjaxBVQlgp+ZaQag9H5idzQlLFZSnvQIuE0S3 KcpZwxBVJvF+vnkkTZTBBqYl1tpiUEqPGwtOUvmM2nhk4oCgiA2K1mN3bYUoiQ==
ARC-Seal i=1; s=2017; d=landit.de; t=1590591843; a=rsa-sha256; cv=none; b=MHPm0+RzT5+lSsDMt7I0Vn/75jm1Rfl4c7ctjmbM47/ZAGy3aJ5pYfa6BtuHXfa9e2nxUe JLYtNG96+t9W7JNOEHEzvREDb2hLSoKibufn/AxkFWEqGBhaztfSHgQjOd1LbFzFhJqmbt gQwK5iMwKuo/fBc+Dmg80xTzQeM8WA2RJQbT5SmYh0Y+MDUvhA4VYlwd92h8IH6umyTLVT NjxVPLGMBDSkRkUS5UQyAjzqjIazlGp/IKVQxjadyhOufiU5CJO5M/XaIZ8bA7rN69C/Fs gPGJs3EPtOAedrOnJxKXl4uOGiObBtWxQtOnh2yCW40xriMBexW11urEtvz49A==
ARC-Authentication-Results i=1; ORIGINATING; auth=pass smtp.auth=gregor@landit.de smtp.mailfrom=gregor@landit.de
Authentication-Results ORIGINATING; auth=pass smtp.auth=gregor@landit.de smtp.mailfrom=gregor@landit.de
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 <e89df817-e4b7-20b3-03f7-c32635f5f769@landit.de>
X-Mailman-Original-References <875zci8zut.fsf@orrococo>
Xref csiph.com de.comp.lang.python:5638

Show key headers only | View raw


Hallo allerseits, hallo Ole,

evtl. könnte man das auch mit dem descriptor-protokoll lösen, so ha ich 
das bei einem sehr aufwendigen Projekt gemacht.
Sehr gutes Tutorial (englisch):
https://www.youtube.com/watch?v=sPiWg5jSoZI
update vom selben Autor:
https://www.youtube.com/watch?v=5nXmq1PsoJ0

https://docs.python.org/3/howto/descriptor.html

Dann kannst du sowas machen:
class Foo:
     myprop = Cfg(init=1.23)

Grüße
Gregor


Am 26.05.20 um 17:44 schrieb Оlе Ѕtrеісhеr:
> 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