REPOST: Re: odd problem, most likely stupid one too :-)

Hans Nowak wurmy at earthlink.net
Sat Dec 29 02:23:05 EST 2001


Dave Harrison wrote:
> 
> Ive written a class named packet, and I have a list on values that I am using to create my packets by passing the values in as I instantiate the classes I am creating.
> 
> I do the creation in a for loop,
> 
> for item in itemlist:
>         PACKET = Packet(item)
>         paclist.append(PACKET)
> 
> except that when I try to go back through and see the packets in my paclist they are all exactly the same as the final one that I store in the list.
> As in I do,
> 
> for pac in paclist:
>         print pac.getVal()
> 
> and I get exactly the same value, despite the fact that I know for sure they are different.
> 
> If I getVal as I create the packets I get the correct and unique values, but once stored I get the oddity.
> 
> Any ideas ?

Hmm... try printing the id() of every instance in paclist...
if they are the same, then you have somehow added the same
instance over and over again to the list. If not, then they
somehow all ended up with the same value, *or* getValue is
doing something wrong.

Oh yeah, and post the code of the Packet class, that might
give us some clues too. ^_^

--Hans

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-nwblwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!newsxfer.interpacket.net!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Hans Nowak <wurmy at earthlink.net>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2D6DF6.64AE27FC at earthlink.net>
Control: cancel <3C2D6DF6.64AE27FC at earthlink.net>
Date: Mon, 31 Dec 2001 01:22:48 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2D6DF6.64AE27FC at earthlink.net>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009774828 27193 211.57.49.2 (31 Dec 2001 05:00:28 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 05:00:28 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.



More information about the Python-list mailing list