Answer the question
In order to leave comments, you need to log in
How to check and remove empty lines?
This script checks certain columns in csv and outputs their value to a file. How to make a pass if there was no value, but now it displays empty lines. Can as that on length of value to check?
import csv
def csv_reader(file_obj):
"""
Read a csv file
"""
reader = csv.DictReader(file_obj, delimiter=';')
for line in reader:
r = (line["Рабочий email"])
l = (line["Личный email"])
e = r.split(',')
d = l.split(',')
base = e + d
with open('data.txt', "a") as file:
for line in base:
file.write(line + '\n')
if __name__ == "__main__":
csv_path = "1.csv"
with open(csv_path, "r", encoding='utf-8') as f_obj:
csv_reader(f_obj)
Answer the question
In order to leave comments, you need to log in
under
r = (line["Рабочий email"])
l = (line["Личный email"])
if not r.strip() and not l.strip():
continue
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question