How to print SRE_Pattern (regexp object) text for debugging purposes?
MRAB
python at mrabarnett.plus.com
Thu Jun 17 19:16:17 EDT 2010
dmtr wrote:
> On Jun 17, 3:35 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
>> >>> import re
>> >>> r = re.compile('^abc$', re.I)
>> >>> r.pattern
>> '^abc$'
>> >>> r.flags
>> 2
>
> Hey, thanks. It works.
>
> Couldn't find it in a reference somehow.
> And it's not in the inspect.getmembers(r).
> Must be doing something wrong.....
>
Occasionally you'll find classes whose instances don't reveal all their
attributes to dir() and so forth, so it's always a good idea to
double-check the documentation.
The documentation mentions the .pattern and .flags attributes at:
http://docs.python.org/library/re.html
Section 7.2.4. Regular Expression Objects
(Python 2.6)
More information about the Python-list
mailing list