Untitled

mail@pastecode.io avatar
unknown
python
a month ago
745 B
1
Indexable
Never
import csv

if __name__ == '__main__':
    folder_for_file = "data/"
    file_format = ".csv"

    filename = 'username'

    file_to_read = folder_for_file + filename + file_format
    file_to_write = folder_for_file + filename + "_copy" + file_format

    with open(file_to_read, mode='r', encoding='utf-8') as csv_file:
        csvreader = csv.reader(csv_file, delimiter=';')

        rows = list([element.strip() for element in row] for row in csvreader)

        for row in rows:
            print(row)

    with open(file_to_write, mode='w', encoding='utf-8', newline='') as csv_write_file:
        csvwriter = csv.writer(csv_write_file, delimiter=';')

        for row in rows:
            csvwriter.writerow(row)
Leave a Comment