468,317 Members | 1,566 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,317 developers. It's quick & easy.

Question regarding re module

Hi,

I have a question regarding re module.
# By the way I'm not in this list, so I'm sorry but please CC me.

I tried following code in Python shell using a regular expression.
Why doesn't the result of dir(reg) have 'pattern', 'flags', and
'groupindex' although they exist as members of _sre.SRE_Pattern
instance ?

It sort of irritates me, because whenever I write Python code
using a module which I'm not used to using, I often try Python
shell with TAB complete to find out the member of module/instance.

Tomohiro Kusumi

-------------------------------------------------
Python 2.5 (r25:51908, May 16 2008, 13:41:55)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import re
reg = re.compile(r"[0-9]+")
reg.pattern
'[0-9]+'
>>reg.flags
0
>>reg.groupindex
{}
>>dir(reg)
['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner',
'search', 'split', 'sub', 'subn']
>>reg.<TAB>
reg.__copy__ reg.finditer reg.search reg.subn
reg.__deepcopy__ reg.match reg.split
reg.findall reg.scanner reg.sub

Jun 27 '08 #1
1 784
Tomohiro Kusumi schrieb:
Hi,

I have a question regarding re module.
# By the way I'm not in this list, so I'm sorry but please CC me.

I tried following code in Python shell using a regular expression.
Why doesn't the result of dir(reg) have 'pattern', 'flags', and
'groupindex' although they exist as members of _sre.SRE_Pattern
instance ?

It sort of irritates me, because whenever I write Python code
using a module which I'm not used to using, I often try Python
shell with TAB complete to find out the member of module/instance.
It could be that the result overloads the __getattr__-method to delegate
calls to some object. Thus it's not part of the outer instance.

Diez
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by It's me | last post: by
reply views Thread by praba kar | last post: by
3 posts views Thread by Samuel | last post: by
2 posts views Thread by Dean R. Henderson | last post: by
3 posts views Thread by John Wright | last post: by
1 post views Thread by m.banaouas | last post: by
3 posts views Thread by Tomohiro Kusumi | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.