Python equivalent of Perl's $/

kyosohma at gmail.com kyosohma at gmail.com
Mon Aug 20 10:17:02 EDT 2007


On Aug 19, 1:13 pm, John K Masters <johnmast... at oxtedonline.net>
wrote:
> I am currently working my way through Jeffrey Friedl's book Mastering
> Regular Expressions. Great book apart from the fact it uses Perl for the
> examples.
>
> One particular expression that interests me is '$/ = ".\n"' which,
> rather than splitting a file into lines, splits on a period-newline
> boundary. Combined with Perl's 'while (<>)' construct this seems a great
> way to process the files I am interested in.
>
> Without wishing to start a flame war, is there a way to do this in Python?
>
> Regards, John
> --
> War is God's way of teaching Americans geography
> Ambrose Bierce (1842 - 1914)

Python has a Regular Expressions module. Check it out here:
http://docs.python.org/lib/module-re.html

There's also a chapter from Dive Into Python that covers this topic
too:
http://www.diveintopython.org/regular_expressions/index.html

Finally, Python "while" statement's docs can be found here:
http://docs.python.org/ref/while.html

Hope that helps!

Mike




More information about the Python-list mailing list