[Tex/LaTex] Python code in LaTeX document

listingspython

I want to include some Python code into LaTex document, so I "imported" the listings package with

\usepackage{listings}

and

\lstdefinelanguage{Python}{
 keywords={typeof, null, catch, switch, in, int, str, float, self},
 keywordstyle=\color{ForestGreen}\bfseries,
 ndkeywords={boolean, throw, import},
 ndkeywords={return, class, if ,elif, endif, while, do, else, True, False , catch, def},
 ndkeywordstyle=\color{BrickRed}\bfseries,
 identifierstyle=\color{black},
 sensitive=false,
 comment=[l]{#},
 morecomment=[s]{/*}{*/},
 commentstyle=\color{purple}\ttfamily,
 stringstyle=\color{red}\ttfamily,
}

when compiling, I get:

 Illegal parameter number in definition oof \lstlang@python$ }

I googled, but I didn't understood how to work the problem out.
it speaks about a command or something similar.

Best Answer

In the LaTeX source you posted, you have an error at:

comment=[l]{#},

Change this to:

comment=[l]{\#},

and it compiles for me.