Re: Comparing types

Discussion in 'Python' started by Terry Reedy, Feb 17, 2013.

  1. Terry Reedy

    Terry Reedy Guest

    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
    Terry Reedy, Feb 17, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    2
    Views:
    587
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    561
    Henry S. Thompson
    Dec 1, 2005
  3. Kill Bill

    Comparing variable types

    Kill Bill, Oct 26, 2003, in forum: Python
    Replies:
    14
    Views:
    468
    Cameron Laird
    Oct 26, 2003
  4. Edward Rutherford

    Comparing fp types for equality

    Edward Rutherford, Dec 20, 2011, in forum: C Programming
    Replies:
    12
    Views:
    420
    Rui Maciel
    Dec 20, 2011
  5. Jason Friedman

    Comparing types

    Jason Friedman, Feb 17, 2013, in forum: Python
    Replies:
    4
    Views:
    113
    Chris Angelico
    Feb 18, 2013
Loading...

Share This Page