Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Comparing types

Thread Tools

Re: Comparing types

Terry Reedy
Posts: n/a
On 2/17/2013 1:34 AM, Jason Friedman wrote:
> I want to tell whether an object is a regular expression pattern.
> Python 3.2.3 (default, Oct 19 2012, 20:10:41)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import re
>>>> s = "hello"
>>>> type(s)

> <class 'str'>
>>>> isinstance(s, str)

> True
>>>> my_pattern = re.compile(s)
>>>> type(my_pattern)

> <class '_sre.SRE_Pattern'>

The .__name__ attribute of the class is '_sre.SRE_Pattern'

>>>> isinstance(my_pattern, _sre.SRE_Pattern)

> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name '_sre' is not defined

but the class is not bound to a (builtin) name, including not to

Terry Jan Reedy

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing types Jason Friedman Python 4 02-18-2013 06:50 AM
Comparing fp types for equality Edward Rutherford C Programming 12 12-20-2011 06:17 PM
Comparing Compact Flash card types Rick S. Digital Photography 12 07-29-2004 06:17 AM
Comparing Compact Flash Card types Rick S. Digital Photography 2 07-19-2004 08:30 PM
Comparing variable types Kill Bill Python 14 10-26-2003 02:55 PM