Problem Commenting within Filehandle Iteration

Wijaya Edward ewijaya at i2r.a-star.edu.sg
Thu Oct 26 09:42:25 CEST 2006


Hi all,
 
I have the following code:
 
 
import sys               
import re                

ham_count = 0            
spam_count = 0
myfile = open('full/index')
for line in myfile.readlines():
    p = re.compile('ham')
    m = p.match(line)
    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?
 
-- 
Edward WIJAYA
SINGAPORE
 
 

------------ Institute For Infocomm Research - Disclaimer -------------
This email is confidential and may be privileged.  If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you.
--------------------------------------------------------



More information about the Python-list mailing list