Dec-07-2020, 08:45 PM
Hi
Hoping someone can help. I am trying to convert a txt file (hundred of lines)- (sample below)
pc_account = An account is an entity (person or company) that applies for or purchases one or more policies from the carrier. Account attributes include years in business, industry code (SIC, NAICS, etc)
By splitting the file into an CSV file that parses out the file into columns by the '=' exist
I have something like this:
thanks in advance for your time.
Hoping someone can help. I am trying to convert a txt file (hundred of lines)- (sample below)
pc_account = An account is an entity (person or company) that applies for or purchases one or more policies from the carrier. Account attributes include years in business, industry code (SIC, NAICS, etc)
By splitting the file into an CSV file that parses out the file into columns by the '=' exist
I have something like this:
import csv with open('S:\descriptions.txt', 'r') as in_file: stripped = (line.strip() for line in in_file) lines = (line.split("=") for line in stripped if line) with open('S:\log.csv', 'w') as out_file: writer = csv.writer(out_file) writer.writerow(('title', 'Defn')) writer.writerows(lines)Any help is appreciated
thanks in advance for your time.