[Tex/LaTex] Pythontex : Input into a pyverbatim environment

pythontex

With the package Pythontex, I want to input a Python file into a pyverbatim environment :

For example, I tried the code :

\begin{pyverbatim}
\input{file_1.py}
\end{pyverbatim}

where file_1.py is a Python file .

But I obtained as result:

\input{file_1.py}

and not the file_1.py's content.

How can I do it?

Update. I tried:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pythontex}
\usepackage{verbatim}

\begin{document}

\begin{pyverbatim}
\VerbatimInput{contenus/fichier_1.py}
\end{pyverbatim}

\end{document}

and I obtained

\VerbatimInput{contenus/fichier_1.py}

as result.

Best Answer

I guess you want \inputpygments:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pythontex}

\begin{document}

Here's the code in the document
\begin{pyverbatim}
def SI(var, unit):
        return '\\SI{' + str(var) + '}{' + unit + '}'
\end{pyverbatim}
and here we load it from a file
\inputpygments{python}{file_1.py}

\end{document}

enter image description here

Related Question