Welcome to Dream.In.Code
Getting Help is Easy!

Join 135,944 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,744 people online right now. Registration is fast and FREE... Join Now!




How to skip blank lines while reading a file in python?

 
Reply to this topicStart new topic

How to skip blank lines while reading a file in python?

gijig
14 May, 2008 - 11:11 PM
Post #1

New D.I.C Head
*

Joined: 14 May, 2008
Posts: 5

Hi all,..please reply
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: How To Skip Blank Lines While Reading A File In Python?
14 May, 2008 - 11:16 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,433



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: How To Skip Blank Lines While Reading A File In Python?
15 May, 2008 - 04:31 AM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
python
infile = open("text.txt","r")

for line in infile:
if not line.strip():
continue
else:
print line

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:46AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month