Question regarding re module

Tomohiro Kusumi kusumi.tomohiro at jp.fujitsu.com
Thu Jun 5 08:11:45 EDT 2008


Diez,

Thanks, you're right.
Delegated attributes are not in the dir() result.

>>> getattr(reg, "pattern")
'[0-9]+'
>>> getattr(reg, "flags")
0
>>> getattr(reg, "groupindex")
{}

Tomohiro Kusumi

>  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 






More information about the Python-list mailing list