Deep vs. shallow copy?

Alex van der Spek zdoor at xs4all.nl
Wed Mar 12 15:25:46 CET 2014


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



More information about the Python-list mailing list