The problem is that \begin{python} needs to see an end-of-line to start it working; and if you comment it, the next one that's seen is too late and the print line is gobbled, so nothing is written out.