Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-29 Thread conan
Thank you, i have read this but somehow a missed it when the issue
arose.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-29 Thread conan
Thank you Paul.

Since the only thing i'm doing is extracting this fields, and have no
plans to include other stuff, a regexp is fine. However i will take
into account 'pyparsing' when i need to do more complex parsing.

As you can see in the example i send, i was trying to get info from a
glade file, in particular i was tired of doing this everytime i need to
access a widget:

some_var = xml.get_widget('some_id')

(doing this is tiresome when you have more than 10 widgets)

So i do a little module to have all widgets instanciated as attributes
of the object, for anyone interested it is on:

http://www.lugmen.org.ar/~p10n/sources/conan/utilidades/GetWidgets.py

However is still pretty unmature, since it lacks some checks.

-- 
http://mail.python.org/mailman/listinfo/python-list


unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-28 Thread conan
This regexp
''

works well with 'grep' for matching lines of the kind


on a XML .glade file

However that's not true for the re module in python, since this one
takes the regexp as if were specified this way: '^'

For some reason regexp on python decide to match from the start of the
line, no matter if you used or not the caret symbol '^'.

I have a hard time to note why this regexp wasn't working:
regexp = re.compile(r'')

The solution was to consider spaces:
regexp = re.compile(r'\s*\s*')

To reproduce behaviour just take a .glade file and this python script:

import re

glade_file_name = 'some.glade'

bad_regexp = re.compile(r'')
good_regexp = re.compile(r'\s*\s*')

for line in open(glade_file_name):
if bad_regexp.match(line):
print 'bad:', line.strip()
if good_regexp.match(line):
print 'good:', line.strip()


The thing is i should expected to have to put caret explicitly to tell
the regexp to match at the start of the line, something like:
r'^'
however python regexp is taking care of that for me. This is not a
desired behaviour for what i know about regexp, but maybe i'm missing
something.

-- 
http://mail.python.org/mailman/listinfo/python-list