OverWrite an existing list in CSV files Python -


i have csv files player attributes:

['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'] 

for example, want check if player center ('2' in position 1 in list) , after want modify 12 element (which '77' peter regin)

how can using csv module ?

import csv   class manipulationfichier:       def __init__(self, fichier):         self.fichier = fichier      def read(self):          open(self.fichier) f:             reader = csv.reader(f)              row  in reader:                 print(row)       def write(self):          open(self.fichier) f:             writer = csv.writer(f)              row in f:                 if row[1] == 2:                      writer.writerows(row[1] row in f) 

which nothing important..

thanks,

in general, csv files cannot reliably modified in-place.

read entire file memory (usually list of lists, in example), modify data, write entire file back.

unless file huge, , often, performance hit negligible.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -