Type object returned by the re.compile function

Jerry Hill malaclypse2 at gmail.com
Tue Dec 27 17:29:25 EST 2011


On Tue, Dec 27, 2011 at 4:56 PM, candide <candide at free.invalid> wrote:
>>>> import re
>>>> reo = re.compile('')
>>>> reo.__class__
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: __class__
>>>>

I'm not going to comment on what type is returned from the various
functions in the re module, mostly because all I have installed
locally is 2.6, and I'm not sure if anything has changed in 2.7 or
3.2.

Instead, I will recommend a different tool for your  toolbox.  Take a
look at the type() builtin function (
http://docs.python.org/library/functions.html#type ).  Particularly,
instead of inspecting reo.__class__ in your example above, you can
print out type(reo).

At a guess, those objects are missing the __class__ attribute,
possibly because they are old style classes.

-- 
Jerry



More information about the Python-list mailing list