A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2002-August/028045.html below:

[Python-Dev] type categories -- an example

[Python-Dev] type categories -- an example [Python-Dev] type categories -- an exampleJeremy Hylton jeremy@alum.mit.edu
Mon, 19 Aug 2002 17:43:01 -0400
>>>>> "AK" == Andrew Koenig <ark@research.att.com> writes:

  AK> How do I test for the third?  I guess I need to know the name of
  AK> the type of a compiled regular expression object.  Hmmm... A
  AK> quick scan through the documentation doesn't reveal it.  So I do
  AK> an experiment:

  >>>> import re re.compile("foo")
  AK>         <_sre.SRE_Pattern object at 0x111018>

  AK> Hmmm... This doesn't look good -- Can I really count on a
  AK> compiled regular expression being an instance of
  AK> _sre.SRE_Pattern for the future?

I'd put this at the module level:

compiled_re_type = type(re.compile(""))

Then you can use isistance() to test:

isinstance(re.compile("spam+"), compiled_re_type)

Jeremy




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4