Problem Commenting within Filehandle Iteration

Fredrik Lundh fredrik at
Thu Oct 26 10:16:23 CEST 2006

Wijaya Edward wrote:

>     if m:
>         print line,
>     else:
>         #print 'SPAM -- %s' % line
> myfile.close()
> Sometime while developing/debugging the code we usually 
> put in such situation. Where expression under "else"
> is not yet supplied, yet we would like see the printout of the
> previous "if" condition. 
> Notice that I wanted to comment out the #print line there.
> However I found problem with myfile.close(), with identation error.
> This error doesn't occur when commenting (#) is not in use.
> Why so?  Is there away to do the commenting in correct way
> under this circumstances?

statement suites cannot be empty in Python (and comments don't count). 
to fix this, insert a "pass" statement:

     if m:
         print line,
         pass # print 'SPAM -- %s' % line

also see:


More information about the Python-list mailing list