473,394 Members | 1,813 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,394 software developers and data experts.

classes and list as parameter, whats wrong?

Hi!

I have a problem in a program. And I don't understand what is going on.
I can code something, that the "error" doesn't occur anymore. But I
still don't know the reason and this is unsatisfactory: Did I understood
something wrong or is there a bug? To make it short, I boiled down the
program to the crucial part. It looks like this:

----------- START ------------
#!/usr/bin/env python

class cClass:
""" Base class to handle playlists, i.e. the files, the name, etc. """
def __init__(self, LL=[]):
self.list=LL
def addFile(self,L):
self.list.append(L)

def main():
l1 = ['a','b','c']
lNames=['n1','n2','n3']
for name in lNames:
objC=cClass()
for each in l1:
objC.addFile(each)
print objC.list
del objC

if __name__ == "__main__":
main()
----------- END ----------------

If I start it, I get the following output:

['a', 'b', 'c']
['a', 'b', 'c', 'a', 'b', 'c']
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
Why does this list grow? I thought, with every new instance the list LL
is set to []?

How can bring light in this?
Best,
Dirk
Aug 26 '05 #1
0 995

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

Similar topics

7
by: Mei | last post by:
I have some classes at the moment that are initialised with their own function rather than a constructor and destructor. I wish this case to be reversed if possible. For arguments sake (you dont...
24
by: Alf P. Steinbach | last post by:
The eighth chapter (chapter 2.1) of my attempted Correct C++ tutorial is now available, although for now only in Word format -- comments welcome! Use the free & system-independent Open Office...
14
by: Josema | last post by:
Hi to all, actually im a newbie in the OOP and i would like to know if this way of using clases its a best way (logical, and a good way) Lets imagine that i have a data base with departments...
8
by: Dave Booker | last post by:
Is the following behavior correct? If so, can somebody explain why? public interface IObservation { string ID { get; set;} } public class Observation { string m_ID; string ID { get {...
5
by: Chris Szabo | last post by:
Good afternoon everyone. I'm running into a problem deserializing a stream using the XmlSerializer. A stored procedure returns the following from SQL Server: <Student StudentId="1" Status="1"...
0
by: Dr. Peer Griebel | last post by:
I'm currently writing a small toy application to support symbolic algebra. Therefore I implemented some classes Term, Var, Number, Sum, Product, Power. These classes are tightly coupled. So it...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.