blank lines representation in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • micklee74@hotmail.com

    #1

    blank lines representation in python

    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

  • Fredrik Lundh

    #2
    Re: blank lines representation in python

    micklee74@hotma il.com wrote:
    [color=blue]
    > 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[/color]

    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>



    Comment

    Working...