473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Someone enlightened me

Can someone explain to me, why the behaviour below is different when u
remark "lister" and unremark "self.lister"?

#--------------------------------------------------------------
class abc :
# remark this later and unremark "self.lister"
lister = []

def __init__ (self, val):
#self.lister = []
self.lister.append(val)

#--------------------------------------------------------------
globallist = []
#--------------------------------------------------------------
def test () :
global l
for x in range(10) :
o = abc(x)
globallist.append(o)
o = ""

for i in globallist :
print i.lister

#--------------------------------------------------------------
test()
#--------------------------------------------------------------
Jul 13 '08 #1
1 1336
On Jul 12, 7:08 pm, Marcus Low <mar...@internetnowasp.netwrote:
Can someone explain to me, why the behaviour below is different when u
remark "lister" and unremark "self.lister"?

#--------------------------------------------------------------
class abc :
# remark this later and unremark "self.lister"
lister = []

def __init__ (self, val):
#self.lister = []
self.lister.append(val)

#--------------------------------------------------------------
globallist = []
#--------------------------------------------------------------
def test () :
global l
for x in range(10) :
o = abc(x)
globallist.append(o)
o = ""

for i in globallist :
print i.lister

#--------------------------------------------------------------
test()
#--------------------------------------------------------------
The way it's written, you're appending to a list associated with the
class itself, which is created only once, then printing out that list
10 times. After you uncomment and comment the specified lines (this is
the usual term, rather than "remark"), you are using a list that is
associated with the actual object, then printing out the 10 different
lists.

Hope that's clear enough.
--Buck
Jul 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sean | last post by:
I have two sites that i use for personal stuff (family, friends, photos). They are PHP sites butim not a programmer. They were setup by a friend who no longer helps with them. There are some...
3
by: Tony Vasquez | last post by:
I am trying to modify my own web site to have a certain type of dynamic background through divs... and such.... but what I need, is help with this one script I have. I want to modify it to work...
6
by: Don | last post by:
Hi, I have the following script that displays a popup window centered in the middle of the screen. I am getting a script error in both IE and Netscape but I don't know what it means. Thanks in...
14
by: bo | last post by:
And why and where one should use one vs. the other? Verbally, it seems like semantics to me--but obviously there is some actual difference that makes references different and or preferable over...
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
9
by: kaeli | last post by:
Hey guys, I found some code I really like. ;) It has who wrote it there, but no contact info. If I attribute the author, is that enough, or should I also try to contact him for permission to...
9
by: bounce | last post by:
Hello, Consider the following HTML: <form action="/cgi-bin/mailmanager.pl" method="post"> <input type="hidden" name="recipient" value="bounce@springbock.net"> <input type="hidden"...
13
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I direct someone to this FAQ? ----------------------------------------------------------------------- ...
0
by: Marcus Low | last post by:
Duh, Ok here is the file again ...attached. I give up doing this via the email editor. Sorry! new to the mailing list. Marcus Marcus Low wrote:
0
by: Marcus Low | last post by:
Opps here is the mail again, incase my formatting is lost, can someone explain to me why this code behaves differently when "lister" and "self.lister" is swap remarked. class abc : # remark...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.