Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #4997
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Thomas Güttler <guettliml@thomas-guettler.de> |
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] __init__ ? |
| Date | Thu, 2 Nov 2017 15:22:01 +0100 |
| Lines | 60 |
| Message-ID | <mailman.168.1509632533.1490.python-de@python.org> (permalink) |
| References | <f60n90F4clsU1@mid.individual.net> <df1ff14f-2de0-19c1-cf1f-42c51e3510ae@thomas-guettler.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="utf-8" |
| X-Trace | news.uni-berlin.de sdDsq4wzu4cXdOTV5vOd/gUkMPUhNBVh+sUqf9xYJX3A== |
| Return-Path | <guettliml@thomas-guettler.de> |
| X-Original-To | python-de@python.org |
| Delivered-To | python-de@mail.python.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
| In-Reply-To | <f60n90F4clsU1@mid.individual.net> |
| Content-Language | de-DE |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.25 |
| X-BeenThere | python-de@python.org |
| X-Mailman-Version | 2.1.25 |
| 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 | <df1ff14f-2de0-19c1-cf1f-42c51e3510ae@thomas-guettler.de> |
| X-Mailman-Original-References | <f60n90F4clsU1@mid.individual.net> |
| Xref | csiph.com de.comp.lang.python:4997 |
Show key headers only | View raw
Prinzipel geht das, aber bei Datentypen die mutable sind (zB Listen) kann
es
zu Konsequenzen kommen, die du ggf nicht haben willst.
class Foo():
my_list = []
Dann teilen sie alle Instanzen der Klasse die gleiche Liste.
Also bei
foo= Foo()
foo.my_list.append(1)
foo2 = Foo()
foo2.append(2)
print foo2
wirst du ggf erstaunt sein.
Am 02.11.2017 um 15:09 schrieb Hermann Riemann:
Bisher habe ich etwas wie
class Cl():
def __init__(self):
self.x=1
gemacht.
So wie das in Buecher ueblich ist.
In einer raspberry pi Zeitschrift habe ich gesehen
dann man stattdessen auch
class Cl():
x=1
schreiben kann.
Hat funktioniert.
( mit c=Cl(); print(c.x); c.x=2; print(c.x) )
Hermann
fragend ob er jetzt viele __init__
bedenkenlos ersetzen kann.
--
Thomas Guettler [1]http://www.thomas-guettler.de/
I am looking for feedback: [2]https://github.com/guettli/programming-guidelines
References
Visible links
1. http://www.thomas-guettler.de/
2. https://github.com/guettli/programming-guidelines
Back to de.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
__init__ ? Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-11-02 15:09 +0100
Re: [Python-de] __init__ ? Thomas Güttler <guettliml@thomas-guettler.de> - 2017-11-02 15:22 +0100
Re: [Python-de] __init__ ? Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-11-02 15:51 +0100
Re: [Python-de] __init__ ? "Diez B. Roggisch" <deets@web.de> - 2017-11-02 15:33 +0100
Re: Python Beispiele SDL2? (was: __init__ ?) Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-11-02 17:28 +0100
Re: [Python-de] Python Beispiele SDL2? (was: __init__ ?) "Diez B. Roggisch" <deets@web.de> - 2017-11-02 18:10 +0100
Re: [Python-de] __init__ ? Stefan Behnel <python-de@behnel.de> - 2017-11-04 07:43 +0100
Re: [Python-de] __init__ ? Dinu Gherman <gherman@darwin.in-berlin.de> - 2017-11-05 18:15 +0100
Re: [Python-de] __init__ ? "Diez B. Roggisch" <deets@web.de> - 2017-11-05 22:09 +0100
Re: [Python-de] __init__ ? Stefan Behnel <python-de@behnel.de> - 2017-11-06 20:57 +0100
Re: [Python-de] __init__ ? Stefan Behnel <python-de@behnel.de> - 2017-11-06 21:28 +0100
Re: [Python-de] __init__ ? "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-11-06 22:29 +0100
Re: [Python-de] __init__ ? "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2017-11-07 11:11 +0000
Re: [Python-de] __init__ ? Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-11-12 18:37 +0100
Re: [Python-de] __init__ ? Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-11-12 19:22 +0100
csiph-web