#!/usr/bin/python3 import sys, getopt, re, csv the_list = "the963_text_document.txt" the_list_csv = "the963.csv" usage_text = 'Usage: specify "go" and we\'ll create a CSV from the list ['+the_list+'].' savedict = {} # saving in dict with "num" as the index, for flexibility; expect 963 total when done. def usage(): print(usage_text) sys.exit(2) def process(the_list): print("Processing ["+the_list+"]:") num = 0 # line number count = 0 # count of people person_rus_found = False person_eng_found = False title_rus_found = False comma_found = False with open(the_list, "r") as f: for line in f: line = line.rstrip() if line == "" or line == "–" or re.match("^.$", line): # empty, dash, or a single character #print( "INFO: skipping line") continue num += 1 print(f'{num : >4}: [{line}]') # If previous line ended with a comma, add this line to it; it's part of the title/description. # Note that there's one entry (#664) with three lines, each of the first two end with commas, # so allow this to repeat as well. if comma_found: savedict[count]['title_rus'] += " "+line print(f"<<