SQLite Forum

Issue importing csv file to db
Login
The following wee python3 script will "fix" your file for you.

```
fh = open('padron_reducido_ruc.txt', 'r', encoding='8859')
fo = open('padron_reducido_ruc.csv', 'w', encoding='utf8')
c = 0
for line in fh:
    row = line.strip(' \r\n').split('|')
    while len(row) < 16:
        row.append(None)
    for idx, item in enumerate(row):
        if item.startswith('"'):
            row[idx] = '"' + item.strip('"').replace('""','"').replace('"','""') + '"'
        elif '"' in item:
            row[idx] = item.replace('""','"').replace('"','""')
    print('|'.join(row), file=fo)
    c += 1
    if c % 1000000 == 0:
        print(c)
print(c)
fh.close()
fo.close()
```

And yes, fixing the quotes fixes the problem.