Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #4997
| From | Thomas Güttler <guettliml@thomas-guettler.de> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] __init__ ? |
| Date | 2017-11-02 15:22 +0100 |
| Message-ID | <mailman.168.1509632533.1490.python-de@python.org> (permalink) |
| References | <f60n90F4clsU1@mid.individual.net> <df1ff14f-2de0-19c1-cf1f-42c51e3510ae@thomas-guettler.de> |
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