[Solved] Creating vertical dictionary from text file


if index==3:
    indexes=line.split("\t")
    for index in indexes:
         Old_Values=Old_Values{[key]} # What here?

As I understand it, what you want there is simply an empty list to put the corresponding elements from the subsequent lines in:

Old_Values[index] = []

Which will give you:

{'WebAddress': [], 'Address': [], 'Surname': [], 'Name': [], 'Telephone': []}

I don’t know where key was coming from, and your function won’t start because while line happens before line is defined (and is redundant anyway). Really, it should look like:

def reading_old_file(self, path):
    old_values = {}
    with open(path) as old_file: # 'r' is the default mode
        for index, line in enumerate(old_file, start=1):
            if index == 3: # just leave out pass cases 
                indexes = line.split("\t")
                for index in indexes:
                    old_values[index] = []
            elif index > 3: # use elif for exclusive cases 
                data = line.split("\t")
                ... # use indexes to put elements in appropriate lists
    print old_values # should probably return something, too

Note compliance with the style guide.

1

solved Creating vertical dictionary from text file