A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-November/050064.html below:

[Python-Dev] Constructor bug

[Python-Dev] Constructor bug [Python-Dev] Constructor bugOliver Walczak oliver.walczak at momatec.de
Mon Nov 22 08:29:17 CET 2004
Dear List,

recently i got stuck on a strange class initialization bug. Please refer the
sample attached for a demonstration and watch what happens to d2 in the
second class instance.
This only works on dictionaries. Any other types initialized outside of
__init__ seem to work perfectly.

So, is it a bug or a feature? In my eyes this behaviour is not what the
programmer has got to expect. Who knows whats happening there and can
explain me if it makes any sense?

Best regards
Oliver
-------------- next part --------------
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

class test:
    d1 = {'key':'value'}
    def __init__(self):
        self.d2 = {'key':'value'}
    
    def Show(self):
        print 'd1=',self.d1
        print 'd2=',self.d2

c1 = test()
print 'c1, before:'
c1.Show()
c1.d1['key'] = 'value2'
c1.d2['key'] = 'value2'
print 'c1, after:'
c1.Show()

c2 = test()
print 'c2:'
c2.Show()
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4