I need to convert DBF file with numeric values into csv file as strings
DBF file column contains numeric data:
NUMBER,C,12 | ...
584413
079711
478293
000865
I use this python function to convert it to csv:
from dbfread import DBF
def dbf_to_csv(dbf_table_pth):#Input a dbf, output a csv, same name, same path, except extension
csv_fn = dbf_table_pth[:-4]+ ".csv" #Set the csv file name
table = DBF(dbf_table_pth)# table variable is a DBF object
with open(csv_fn, 'w', encoding='utf-8', newline = '') as f:# create a csv file, fill it with dbf content
writer = csv.writer(f, dialect='excel')
writer.writerow(table.field_names)# write the column name
for record in table:# write the rows
writer.writerow(list(record.values()))
return csv_fn# return the csv name
It leads to csv-result below, when I open it in notepad:
NUMBER, ...
"584413,0", ...
"79711,0", ...
"478293,0", ...
"865,0", ...
How can I improve func to get results like this?:
NUMBER, ...
584413, ...
079711, ...
478293, ...
000865, ...