I'm trying to create a .csv file and then create a .gz file with the previous csv inside. The problem is that the .gz file is created with a file with the correct file name but without the .csv extension and I don't know how to solve it.
This is the relevant code:
new_file_name = 'test'
data = [['some','test'],['data','strings']]
csv_fname = '%s.csv' % new_file_name
tar_fname = '%s.gz' % new_file_name
with open(csv_fname, 'wb') as csvfile:
swriter = csv.writer(csvfile)
for row in data:
swriter.writerow(row)
print 'creating archive'
out = tarfile.open(tar_fname, 'w:gz')
try:
print 'adding %s' % csv_fname
out.add(csv_fname)
finally:
print 'closing'
out.close()