# How to use \lstinline inside figure environment's caption argument [duplicate]

Here is the code that I have (I have removed parts which I think are not relevant):

\documentclass[12pt]{article}

\usepackage{listings}

% Python style for highlighting
language=Python,
...
}}

% Python environment
\lstnewenvironment{python}[1][]
{
\pythonstyle
\lstset{#1}
}
{}

% Python for inline
\newcommand{\pythoninline}[1]{{\pythonstyle\lstinline!#1!}}

\begin{document}

\begin{figure}
\begin{python}
def function_name():
...
\end{python}
\caption{Definition of the function_name function.}
\end{figure}

\end{document}


What I would like to do is to use the command \pythoninline inside the figure caption argument. This does not work:

\caption{Definition of the \pythoninline{function_name} function.}


Any suggestions would be much appreciated.