我有一個CSV文件與球員屬性:覆蓋現有列表中的CSV文件的Python
['Peter Regin', '2', 'DAN', 'N', '1987', '6', '6', '199', '74', '2', '608000', '', '77', '52', '74', '72', '58', '72', '71', '72', '70', '72', '74', '68', '74', '41', '40', '51']
['Andrej Sekera', '8', 'SVK', 'N', '1987', '6', '6', '198', '72', '3', '1323000', '', '65', '39', '89', '78', '75', '70', '72', '56', '53', '56', '57', '72', '57', '59', '70', '51']
例如,我要檢查,如果一個球員是一箇中心(「2」在我的列表中的位置1 )後,我想修改12元素(這是彼得雷金'77')
我該怎麼做,使用CSV模塊?
import csv
class ManipulationFichier:
def __init__(self, fichier):
self.fichier = fichier
def read(self):
with open(self.fichier) as f:
reader = csv.reader(f)
for row in reader:
print(row)
def write(self):
with open(self.fichier) as f:
writer = csv.writer(f)
for row in f:
if row[1] == 2:
writer.writerows(row[1] for row in f)
裏面做什麼都不重要..
感謝,
你能告訴我們你到目前爲止的代碼嗎? – 2013-05-13 23:59:17