Looking for Form Feeds

Fredrik Lundh fredrik at pythonware.com
Mon Jan 24 16:43:38 EST 2005


Greg Lindstrom wrote:

> I have a file generated by an HP-9000 running Unix containing form feeds signified by ^M^L.  I am 
> trying to scan for the linefeed to signal certain processing to be performed but can not get the 
> regex to "see" it.  Suppose I read my input line into a variable named "input"
>
> The following does not seem to work...
> input = input_file.readline()
> if re.match('\f', input): print 'Found a formfeed!'
> else: print 'No linefeed!'

hint:

    >>> line = "\r\f"
    >>> re.match("\f", line)
    (nothing)
    >>> re.search("\f", line)
    <_sre.SRE_Match object at 0x00B380C8>
    >>> re.match("\r\f", line)
    <_sre.SRE_Match object at 0x00B38988>

in this case, it's probably better to use the "in" operator:

    if "\f" in line:
        print "found a line feed"

</F> 






More information about the Python-list mailing list