Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6659575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:03:01+00:00 2026-05-26T02:03:01+00:00

While using the re module in ipython I noticed an undocumented template function: In

  • 0

While using the re module in ipython I noticed an undocumented template function:

In [420]: re.template?
Type:           function
Base Class:     <type 'function'>
String Form:    <function template at 0xb7eb8e64>
Namespace:      Interactive
File:           /usr/tideway/lib/python2.7/re.py
Definition:     re.template(pattern, flags=0)
Docstring:
    Compile a template pattern, returning a pattern object

there is also a flag re.TEMPLATE and its alias re.T.

None of this is mentioned in the docs for either 2.7 or 3.2. What do they do? Are they obsolete hangovers from an earlier version of Python, or an experimental feature that may be officially added in the future?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:03:01+00:00Added an answer on May 26, 2026 at 2:03 am

    In CPython 2.7.1, re.template() is defined as:

    def template(pattern, flags=0):
        "Compile a template pattern, returning a pattern object"
        return _compile(pattern, flags|T)
    

    _compile calls _compile_typed which calls sre_compile.compile. The only place in the code where the T (aka SRE_FLAG_TEMPLATE) flag is checked is in that function:

        elif op in REPEATING_CODES:
            if flags & SRE_FLAG_TEMPLATE:
                raise error, "internal: unsupported template operator"
                emit(OPCODES[REPEAT])
                skip = _len(code); emit(0)
                emit(av[0])
                emit(av[1])
                _compile(code, av[2], flags)
                emit(OPCODES[SUCCESS])
                code[skip] = _len(code) - skip
        ...
    

    This would have the effect of disabling all repetition operators (*, +, ?, {} etc):

    In [10]: re.template('a?')
    ---------------------------------------------------------------------------
    .....
    error: internal: unsupported template operator
    

    The way the code is structured (the unconditional raise preceding a bunch of dead code) makes me think that the feature was either never fully implemented, or has been turned off due to some problems. I can only guess what the intended semantics may have been.

    The end result is that the function does nothing useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While using the repository module I noticed Attribute and Values in module setting. What
I am using fancybox module for image display in drupal 6. and while changing
When using module threading and class Thread() , I can't catch SIGINT ( Ctrl
We're using DotNetNuke 5.01. I've downloaded a module from a third party company. While
I use L2S at my module. The problem occurs while I'm using the default
While using Struts2, I am using several annotations to do my validations inside the
While using Vim (at home and at work), I often find myself doing similar
While using regex to help solve a problem in the Python Challenge , I
While using the vector why do we sometime use the operator[] like homework[mid] but
While using Aptana and Eclipse for the first time in my programming life for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.