# Problem with listings package for Python syntax coloring

I am implementing the method I learned here for putting Python code in Latex. Everything works great except that I have problems with comments. Here's the code from the link I mentioned:

\usepackage[utf8]{inputenc}
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{9} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{9}  % for normal
% Defining colors
\usepackage{color}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}

\usepackage{listings}

% Python style for highlighting
\newcommand\pythonstyle{\lstset{
language=Python,
backgroundcolor=\color{white}
basicstyle=\ttm,
otherkeywords={self},
keywordstyle=\ttb\color{deepblue},
emph={MyClass,__init__},
emphstyle=\ttb\color{deepred},
stringstyle=\color{deepgreen},
frame=tb,
showstringspaces=false
}}

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


I use the following function, python, defined in the code, to generate Python code:

\begin{python}
class MyClass(Yourclass):
def __init__(self, my, yours):
String = "String"
String2 = '5 1 2 3 4'
print String2
import numpy as np #Comment1
# Comment2
\end{python}


This is the result. I see two frame words for each comment. Do you know what can be wrong here? The link that I mentioned works perfectly in every other aspect. Thanks.

you have some missing comma:

\newcommand\pythonstyle{\lstset{
language=Python,
backgroundcolor=\color{white}, %%%%%%%
basicstyle=\ttm,
otherkeywords={self},
keywordstyle=\ttb\color{deepblue},
emph={MyClass,__init__},
emphstyle=\ttb\color{deepred},
stringstyle=\color{deepgreen},
frame=tb,
showstringspaces=false
}}

• Great! It solved the problem. Interestingly enough, the two lines with missing ,, were the only lines I had added from somewhere else! – ahoosh Sep 3 '14 at 19:56