Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18068

Re: Type object returned by the re.compile function

References <4efa3f05$0$6546$426a74cc@news.free.fr>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-12-27 15:31 -0700
Subject Re: Type object returned by the re.compile function
Newsgroups comp.lang.python
Message-ID <mailman.4159.1325025123.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Dec 27, 2011 at 2:56 PM, candide <candide@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Type object returned by the re.compile function candide <candide@free.invalid> - 2011-12-27 22:56 +0100
  Re: Type object returned by the re.compile function Jerry Hill <malaclypse2@gmail.com> - 2011-12-27 17:29 -0500
  Re: Type object returned by the re.compile function Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 15:31 -0700

csiph-web