python cfreportlatex.py example.txt
\begin{table}
\caption{Latex Table from Classification Report}
\label{table:classification:report}
\centering
\begin{tabular}{c | c c c r}
Class & Precision & Recall & F-score & Support\\
\midrule
0 & 0.98 & 0.88 & 0.93 & 14404\\
1 & 0.35 & 0.82 & 0.5 & 217\\
2 & 0.54 & 0.77 & 0.64 & 502\\
3 & 0.32 & 0.77 & 0.45 & 246\\
4 & 0.54 & 0.76 & 0.63 & 984\\
5 & 0.69 & 0.78 & 0.73 & 23\\
6 & 0.59 & 0.75 & 0.66 & 36\\
7 & 0.33 & 0.86 & 0.48 & 80\\
\midrule
micro avg & 0.87 & 0.87 & 0.87 & 16492\\
macro avg & 0.54 & 0.8 & 0.63 & 16492\\
avg & 0.92 & 0.87 & 0.88 & 16492\\
\end{tabular}
\end{table}
Had problems with the code since the classification report throws an extra row 'accuracy' with no values under precision and recall columns. Showed me "not enough values to unpack (expected 4, got 2)". Added a line after removing empty lines in parse_clasification_report() to remove the accuracy line from the list.
lines=[s for s in lines if 'accuracy' not in s]