This is my csv file named 'test.csv':
aaa,,
ccc,ddd,
,eee,
And this is my code:
import csv
with open('test.csv', 'rt') as f:
a = list(csv.reader(f))
r = a[:]
for row in r:
for index in range(3):
if row[index] == '':
row[index] = 'xxx'
print(r)
print(a)
The result:
[['aaa','xxx','xxx'],['ccc','ddd','xxx'],['xxx','eee','xxx]]
[['aaa','xxx','xxx'],['ccc','ddd','xxx'],['xxx','eee','xxx]]
I only want to change the content in list 'r', but why the list 'a' didn't remain the original one [['aaa','',''],['ccc','ddd',''],['','eee','']]?