simple question on persisting variable values in a list

dgrissen at gmail.com dgrissen at gmail.com
Tue Nov 20 16:25:05 EST 2007


Hi,

I am an unabashed noob.

I am trying to build a list to store values that are generated through
a loop.  However, every time I append the variable to the list, I'd
like to reset the variable, but have the value persist in the loop.  I
understand why this doesn't work because it's a reference not a
literal value but have been unsuccessful at using copy.copy() or
anything else to accomplish this:


for char in splitlines[r]:

            if char == "\n":
                temp = copy.deepcopy(templine)
                individline.append(temp)
                templine = ""
            else:
                templine += char

results.append(individline)


This just gives me the last element in splitlines[r] - what i want is
to persist each line that is parsed from splitlines[] into the results
list.

Appreciate any help,,,



More information about the Python-list mailing list