mercredi 12 mars 2014

Deep vs. shallow copy? topic




I think I understand the difference between deep vs. shallow copies but
I was bitten by this:

with open(os.path.join('path', 'foo.txt', 'rb') as txt:
reader = csv.reader(txt)
data = [row.append(year) for row in reader]

This does not work although the append does complete. The below works:

with open(os.path.join('path', 'foo.txt', 'rb') as txt:
reader = csv.reader(txt)
data = [row + [year] for row in reader]

However in this context I am baffled. If someone can explain what is
going on here, I would be most grateful.

Alex van der Spek





Aucun commentaire:

Enregistrer un commentaire