Найти - Пользователи
Полная версия: python2 regex xml
Начало » Python для новичков » python2 regex xml
1
papuas
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from xml.dom.minidom import *
xml = parse('test.xml')
name = xml.getElementsByTagName('ip')
ip = set()
for node in name:
    i = ip.add(node.childNodes[0].data.encode('utf-8'))
mo = re.match(r'^\\d{1,3}\.\\d{1,3}\.\\d{1,3}\.\\d{1,3}$',i)
print mo.group(0)

Traceback (most recent call last):
  File "/home./test.py", line 10, in <module>
    mo = re.match(r'^\\d{1,3}\.\\d{1,3}\.\\d{1,3}\.\\d{1,3}$',i)
  File "/usr/lib/python2.7/re.py", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer


re.match(pattern, string)
как то можно на ввод в string подать node.childNodes ?
пока не нашел другую конструкцию.
направьте пж на путь истинный.
py.user.next
В i ничего нет.
papuas
py.user.next
В i ничего нет.
Нужно задать переменную ноде ip set childNode ?
py.user.next
>>> import re
>>> 
>>> s = {'a', 'b', 'c', 'dd'}
>>> pat = re.compile(r'^.$')
>>> filter(pat.match, s)
['a', 'b', 'c']
>>>
papuas
спасибо за наводку compile
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB