473,414 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Problem Commenting within Filehandle Iteration


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.
--------------------------------------------------------
Oct 26 '06 #1
1 1235
In <ma***************************************@python. org>, Wijaya Edward
wrote:
if m:
print line,
else:
#print 'SPAM -- %s' % line
myfile.close()

[…]

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?
There has to be code in the ``else`` block. So either comment out the
``else`` line too, or insert a ``pass`` statement.

Ciao,
Marc 'BlackJack' Rintsch
Oct 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy Jackson | last post by:
Hello all. Okay, this seems really stupid, but it's driving me up the wall. I have a simple script I've written to log some information to a text file. Everything seems to be okay, the code...
18
by: Chris | last post by:
Hello, I have an unordered list with 3 levels, like this: <ul class="normalList"> <li>blabla</li> <ul> <li>blabla</li> </ul> <li>blabla</li> <ul>
7
by: Mike | last post by:
Hi, I have an iteration to retrieve a number of messages from a server. Within this iteration, I am using the following code: do { readBytes = base.GetStream().Read(received, 0,...
4
by: kscdavefl | last post by:
I am trying to iterate through a datagrid using the following code: private void updateFCA(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { for (int i = 0; i <...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
4
by: Ernesto | last post by:
I'm just want to read in the contents of a (text) file. The text file is filled with semiColon delimited floating point strings... 0.456;1.265;99.742;... For some reason, I can't get the...
0
by: P Pulkkinen | last post by:
Dear all, sorry, i know this code is far little too long to debug here, but there is really annoying logical error. If someone debugs this, I really offer warm virtual handshake. What this...
2
by: CSUIDL PROGRAMMEr | last post by:
I am new to python. so be patient with me I am trying to redirect the output of os.popen command to a file. I want to append to that file. but instead of appending. The file only shows last...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.