En la linea "Ăștiles inĂștiles", me acabo de encontrar con esto; por si a alguien le interesa:

Source: http://code.activestate.com/recipes/384122-infix-operators/
Modulo: http://pypi.python.org/pypi/inrex/1.1.1

easy_install inrex

from inrex import  match, search, split, findall, finditer

if 'asd 123' |match| r'(\w+) (\d+)':
    print 'word is', match[0]
    print 'digit is', match[1]

if 'asd 123' |match| r'(?P<word>\w+) (?P<digit>\d+)':
    print 'word is', match['word']
    print 'digit is', match['digit']

print 'asd 123 qwe 456' |findall| r'\d+'
print 'asd 123 qwe 456' |split| r'\d+'
print 'asd 123 qwe 456' |split(maxsplit=1)| r'\d+'

with open("logfile.txt") as f:
    for m in f |match| r"(\w+) (\w+) (\w+)":
        print match[0], match[1], match[2]
        # or
        print m.group(0), m.group(1), m.group(2)

--
Ferran at fompi.net
another sexy techie
_______________________________________________
Python-es mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Responder a