I have .tex file and i want to add to it code that I generated with PyLaTeX. How can I do it? This is what I have by now.
with open('file1.tex', encoding='utf-8') as file:
tex = file.read()
doc = Section('a')
doc.append(NoEscape(tex))
#code for generating and adding plots (not important)
doc.generate_tex('file2')
But this way I get
\section{a}%
\label{sec:a}%
at the beginning of my .tex file, and also I have to move \end{document} at the end of my code.