Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you're looking for someone who will solve a whole problem for you. Here I am :)</p> <p>General idea is to parse general info to dict (using regular expressions), then append additional fields to it and finally write to CSV. Here's Python 3.x solution (I think Python 2.7+ should suffice):</p> <pre><code>import csv import re def read_general(fname): # Read general info to dict with 'PR 123'-like keys # Gerexp that will split row into ready-to-use dict re_name = re.compile(r''' (?P&lt;Name&gt;.+) \ --\ # Separator + space (?P&lt;Division&gt;.+) \ # Space \( (?P&lt;Division_Abbreviation&gt;.*) \) \ # Space (?P&lt;Id&gt;\d+) \ # Space \[Age:\ # Space at the end (?P&lt;Age&gt;\d+) \] ''', re.X) general = {} with open(fname, 'rt') as f: for line in f: line = line.strip() m = re_name.match(line) if m: # Name line, start new man man = m.groupdict() key = '%s %s' % (m.group('Division_Abbreviation'), m.group('Id')) general[key] = man elif line: # Non empty lines # Add values to dict key, value = line.split(': ', 1) man[key] = value return general def add_bool_criteria(fname, field, general): # Append a field with YES/NO value with open(fname, 'rt') as f: yes_keys = set() # Phase one, gather all keys for line in f: line = line.strip() _, keys = line.split(': ', 1) yes_keys.update(keys.split(', ')) # Fill data for key, man in general.items(): # iteritems() will be faster in Python 2.x man[field] = 'YES' if key in yes_keys else 'NO' def save_csv(fname, general): with open(fname, 'wt') as f: # Gather field names all_fields = set() for value in general.values(): all_fields.update(value.keys()) # Write to csv w = csv.DictWriter(f, all_fields) w.writeheader() w.writerows(general.values()) def main(): general = read_general('general.txt') add_bool_criteria('cars.txt', 'Car?', general) add_bool_criteria('house.txt', 'House?', general) from pprint import pprint pprint(general) save_csv('result.csv', general) if __name__ == '__main__': main() </code></pre> <p>I wish you lot of $$$ for this ;)</p> <h2>Side note</h2> <p>CSV is a history, you could use JSON for storage and further use, because it's simpler to use, more flexible and human readable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload