Ideally, you should use the Python csv
module. Imagine you have a CSV file like the following:
CAMPO1;CAMPO2;CAMPO3
21890;BH Telecom (PTT BiH, GSMBIH);Bosnia and Herzegovina
21891;BH Telecom (PTT BiH, GSMBIH);Germany
21892;BH Entel;China
You can do something like this:
import csv
archivo = open('archivo.csv')
reader = csv.reader(archivo, delimiter=';')
cabecera = reader.next()
print 'Cabecera:', cabecera
for fila in reader:
print '-' * 50
imsi = fila[0]
operador = fila[1]
pais = fila[2]
print 'IMSI:', imsi
print 'Operador:', operador
print 'Pais:', pais
print '-' * 50
The result of the previous code is:
Cabecera: ['CAMPO1', 'CAMPO2', 'CAMPO3']
--------------------------------------------------
IMSI: 21890
Operador: BH Telecom (PTT BiH, GSMBIH)
Pais: Bosnia and Herzegovina
--------------------------------------------------
IMSI: 21891
Operador: BH Telecom (PTT BiH, GSMBIH)
Pais: Germany
--------------------------------------------------
IMSI: 21892
Operador: BH Entel
Pais: China
--------------------------------------------------
Notice that the reader
I'm passing the delimiter ;
(by default is the comma) and that I'm getting rid of the header before starting the loop with this line:
cabecera = reader.next()