I have a long text file where i was able to extract these lines by grabing just the ones that contain the word "Average":
Average time per layer:
Average Forward pass: 4013.65 ms.
Average Backward pass: 7425.13 ms.
Average Forward-Backward: 11480.2 ms.
Here is what I need in a csv file so I can easily make a graph:
Average Forward pass 4013.65
Average Backward pass 7425.13
Average Forward-Backward 11480.2
Here is the output I'm getting:
: 7425.13 ms.
: 11480.2 ms.
:
: 4013.65 ms.
Here is what i have but it doesn't give me the right results:
def parse_output(outputName):
"This reads the parsed file and formated it to a map"
with open(outputName,'r') as parsedFile:
entry = {}
for line in parsedFile:
key, value = map(line.strip, line.split(':',1))
entry[key] = value
yield entry
def print_csv(outputName, csvFile):
"This reads the map and print it to csv"
remove_file_exist(csvFile)
for foo in parse_output(outputName):
with open(csvFile, 'a') as csvFile:
for entry in foo:
csvFile.write(str(entry))
print(entry)
print(foo);
I've tried to convert the original text to json, but didn't get it to work. any input will be appreciate it. I'm very very new to python. This is my first script in this language.
jsonfor jsoncsvfor csv