how do I express this perl idiom in python?

Michael Vanier mvanier at endor.bbb.caltech.edu
Wed Aug 2 19:11:52 EDT 2000


Hi,

Perl allows you to redefine the end-of-line marker (using the special
variable $/, which is a newline by default) into an arbitrary string, so that
you can grab everything up to and including that string.  For instance:

    $/ = "foobar";
    $line = <FILE>;

will put all the file characters from the beginning of the file until the
string "foobar" is reached into the variable "$line".  The "foobar" string is
also put into "$line", I believe (correct me if I'm wrong; I'm not a perl
programmer).  This can be useful when parsing HTML or XML files, for
instance.

Is there some not-too-painful way to do this in python, or in a python
module?  I know about the HTMLParser class, but I want something more
general.

Thanks,

Mike


--------------------------------------------------------------
Mike Vanier	mvanier at bbb.caltech.edu
Department of Computation and Neural Systems, Caltech 216-76
GNU/Linux: We can't lose; we're on a mission from God.



More information about the Python-list mailing list