Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7254] Class members not properly initialized if declared outside of function

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 2, 2009, 1:55 PM

Post #1 of 2 (71 views)
Permalink
[issue7254] Class members not properly initialized if declared outside of function

New submission from Vlad <vladc6[at]yahoo.com>:

If a class member is declared outside of a function, it's creation is
_not_ repeated with every new instance of the class. Instead, the same
member is created during the first instance and then shared by all the
subsequent instances of that class. This is wrong, because a new member
should be created for every instance.

I have attached a sample code contrasting the incorrect behavior (on
top) with the correct behavior (on bottom). Python behaves correctly if
the member is declared in __init__ (that is, Python initializes a new
member for every instance).

The output of "print b.greet" and "print d.greet" should be the same and
should read "['Howdy']".

----------
files: class_member_init_inconsistency.py
messages: 94851
nosy: vladc6
severity: normal
status: open
title: Class members not properly initialized if declared outside of function
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file15253/class_member_init_inconsistency.py

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue7254>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 2:18 PM

Post #2 of 2 (57 views)
Permalink
[issue7254] Class members not properly initialized if declared outside of function [In reply to]

R. David Murray <rdmurray[at]bitdance.com> added the comment:

This is the way python works. For help on using python please post to
python-list or python-tutor.

----------
nosy: +r.david.murray
priority: -> low
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue7254>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.