blank lines representation in python

M

micklee74

hi
what is the correct way to represent blank lines in python (while
iterating a file) without regexp? I know one way is to use
re.search((line,r'^$') to grab a blank line, but i wanna try not to use
regexp...
is it
1) if line == ''": dosomething() (this also means EOF right? )
2) if line is None: dosomething()
3) if not line: dosomething()
thanks
 
F

Fredrik Lundh

what is the correct way to represent blank lines in python (while
iterating a file) without regexp? I know one way is to use
re.search((line,r'^$') to grab a blank line, but i wanna try not to use
regexp...
is it
1) if line == ''": dosomething() (this also means EOF right? )
2) if line is None: dosomething()
3) if not line: dosomething()
thanks

if line == "\n": # look for a single newline
dosomething()

or

if not line:
... end of file ...
elif not line.strip(): # look for lines with nothing but whitespace
dosomething()

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,202
Latest member
ClaudioVil

Latest Threads

Top