[Tutor] Strange Appending
cyresse at gmail.com
Fri Dec 3 04:02:24 CET 2004
What's t supposed to be, what are you initialising self.a as, where is
t generated, what is your expected output? What else is happening to
Looks like an indentation error to me.
This kind of output
[[1, 237, 543], [1, 237, 543], [1, 237, 543], [1, 237, 543]]
would only come from
a loop iterating over the command that appends [1,237,543] several times.
I'd check your logic, logical errors are the hardest.
I use that kind of thing often -
a="Hello 123, How is 456?"
for item in a:
But yeah, post up all the relevant code please, just not the bit
that's not breaking. I can't see your loop that's writing the wrong
values, or perhaps self.a is getting reinitialized wrong? If you get
On Thu, 2 Dec 2004 14:41:03 -0800 (PST), Marilyn Davis
<marilyn at deliberate.com> wrote:
> On Thu, 2 Dec 2004, mdcooper wrote:
> > Hello,
> > I am trying to append a list to another list, but everytime I do, the new
> > parent list has a new child list, but all the other lists have become the same
> > as the new child list.
> > Code:
> > self._f.write(str(self.residue.atoms[int(t)-1].element) + ' ')
> > for m in t:
> > self._f.write(str(m)+' ')
> > self._f.write('\n')
> > self.a.append(t) # WHY DOES THIS NOT WORK?????
> I'm not sure that I understand your question because I don't see all
> the code and I don't know what you hope will happen. But ...
> append appends the object as a single element.
> Try self.a.extend(t)
> extend attaches the t list to the end of the list.
> Does this give you what you expect?
> Marilyn Davis
> > print self.a
> > Output:
> > [[1, 234, 543]]
> > [[1, 234, 548], [1, 234, 548]]
> > [[1, 234, 59], [1, 234, 59], [1, 234, 59]]
> > [[1, 237, 543], [1, 237, 543], [1, 237, 543], [1, 237, 543]]
> > Can anyone help?
> > thanks,
> > Matthew (mdcooper at uvic dot ca)
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> Tutor maillist - Tutor at python.org
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor