[Tex/LaTex] “Improper alphabetic constant” with listings customized

beamerlistings

When I attempt to compile my Beamer slides (very much trimmed-down code below), I encounter the following error:

! Improper alphabetic constant.
<to be read again> 
                   \relax 
l.1 \begin{python}

The Beamer slides code contains listings syntax highlighting customizations and is shown below. What might be going wrong?

\documentclass{article}

\usepackage{listings}
\newcommand\pythonstyle{\lstset{
       language=Python,
       otherkeywords={self,},
}}
\lstnewenvironment{python}[1][]{
    \pythonstyle
    \lstset{#1}
}{}

\begin{document}

\begin{python}
import multiprocessing
\end{python}

\end{document}

Best Answer

After removing the 90% or more of your code that was completely irrelevant, we are left with the following chunk that is broken:

\documentclass{article}

\usepackage{listings}
\newcommand\pythonstyle{\lstset{
       language=Python,
       otherkeywords={self,},
}}
\lstnewenvironment{python}[1][]{
    \pythonstyle
    \lstset{#1}
}{}

\begin{document}

\begin{python}
import multiprocessing
\end{python}

\end{document}

Commenting out the line otherkeywords={self,}, makes the problem go away, so a reasonable guess is that the problem is the comma after self. Sure enough deleting the comma fixes the problem.