Type object returned by the re.compile function

Ian Kelly ian.g.kelly at gmail.com
Tue Dec 27 17:31:30 EST 2011


On Tue, Dec 27, 2011 at 2:56 PM, candide <candide at free.invalid> wrote:
> The Python 2.7 official documentation here:
>
> http://docs.python.org/library/re.html#re.compile
>
> doesn't specify the type object returned by the re.compiled function.
> According to the documentation, re.compile returns a "regular expression
> object".
>
> A regular expression object seems to be an instance of the class
> RegexObject. The documentation mentions this class here :
>
> http://docs.python.org/library/re.html#regular-expression-objects
>
> but i don't see any existing class with this name :

Presumably if it's not in the module then it's not meant to be
directly invoked.  You should always use re.compile().  If you really
want to assign the type a name, though:

>>> import re
>>> RegexObject = type(re.compile(''))
>>> RegexObject
<type '_sre.SRE_Pattern'>

Cheers,
Ian



More information about the Python-list mailing list