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


Groups > comp.lang.python > #39025 > unrolled thread

Re: Comparing types

Started byTerry Reedy <tjreedy@udel.edu>
First post2013-02-17 04:42 -0500
Last post2013-02-17 04:42 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Comparing types Terry Reedy <tjreedy@udel.edu> - 2013-02-17 04:42 -0500

#39025 — Re: Comparing types

FromTerry Reedy <tjreedy@udel.edu>
Date2013-02-17 04:42 -0500
SubjectRe: Comparing types
Message-ID<mailman.1891.1361094162.2939.python-list@python.org>
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 
_sre.SRE_Pattern



-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web