Expresiones Regulares
inf200468 en ucf.edu.cu
inf200468 en ucf.edu.cu
Vie Feb 15 17:01:30 CET 2008
?como puedo definir un
patron para la ip y otro
para la fecha,
yo leo el fichero con un while linea
a linea?
asi?
import sys
import os
import re
#PATRONES A BUSCAR
patron_IP =
re.compile('[10-256]..[0-255]..[0-255]..[0-255]')
patron_FECHA =
re.compile('[00-31]./.*./.*.:[00-60]')
if(os.path.exists('D:\\log')):
??? try:
??????? fichero = open('D:\\log','r')
??? except:
???????
print 'no
se pudo abrir el fichero'
??????? sys.exit()
#ESTE WHILE LEE
LINEA A LINEA DEL FICHERO Y CON E.R SACA LA IP DE LAS LINEAS
??? linea =
fichero.readline()
??? while
(linea):
??????? iterator =
patron_IP.finditer
(linea)
??????? for result in iterator:
???????????
print
linea[result.start():result.end()]
??????? i =
patron_FECHA.finditer (linea)
??????? for result in i:
??????????? print
linea[result.start():result.end()]
??????? linea = fichero.readline()
??? fichero.close() #CIERRO EL FICHERO
else:
??? print "No
Existe el camino"
???
sys.exit()
------------------------------
Participe en Universidad 2008
11 al 15 de febrero del 2008
Palacio de las Convenciones,
Ciudad de la Habana, Cuba
http://www.universidad2008.cu
------------ próxima parte ------------
An embedded and charset-unspecified text was scrubbed...
Name: untitled-1.2
URL: <http://mail.python.org/pipermail/python-es/attachments/20080215/76969675/attachment.ksh>
------------ próxima parte ------------
An embedded and charset-unspecified text was scrubbed...
Name: untitled-2
URL: <http://mail.python.org/pipermail/python-es/attachments/20080215/76969675/attachment-0001.ksh>
------------ próxima parte ------------
_______________________________________________
Lista de correo Python-es
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
Más información sobre la lista de distribución Python-es