faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

Perl problem in Python

Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 233, Magnus L. Hetland


"""
Packages: text.regular_expressions
"""
"""
>I want to learn Python to replace Perl as my scripting language of
>choice.  Something that'd be helpful is maybe a list of "Here's how you do
>that in Python" items for typical Perl code.
>For example, what about the typical Perl script that filters out lines
>from standard input:
>while (<>) {
>    next if /xxxx/;
>    print if /yyyy/;
>    (etc.)
}
"""
from fileinput import input
from re import match
for line in input():
    if match('xxxx',line): continue
    if match('yyyy',line): print line