So I have a .txt file and I want to use methods within this class, Map
, to append its contents into a aDictionary
.
class Map:
def __init__(self, dataText):
self.dataText = dataText
self.aDictionary = {}
dataFile = open('data.txt', 'r')
c1 = Map(dataFile)
My data.txt
file looks something like this:
hello, world
how, are
you, today
and I want aDictionary
to print this output:
{how: are, you: today}
Im not very good at manipulating files as I continue to get type errors and what not. Is there an easy way of performing this task using methods within the class?