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 8836363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:28:39+00:00 2026-06-14T09:28:39+00:00

I have a python file filled with functions like h1 and img and strong

  • 0

I have a python file filled with functions like h1 and img and strong for use styling text. Each of these functions are defined as follows:

def _wrapTag(tag, text, **attributes):
    out = _createTag(tag, **attributes)
    out += text
    out += "</" + tag + ">"
    return out

def _createTag(tag, **attributes):
    out = "<" + tag
    if attributes:
        for attr, value in attributes:
            out += " " + attr + "=\"" + value + "\""
    out += ">"
    return out

def h2(text, **attributes):
    return _wrapTag("h2", text, **attributes)

In an ideal world, to create a div with the class modal, I would call div(content, class="modal") however class is a restricted keyword. Is there any way to bypass this without adding a special case to _createTag?

  • 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-06-14T09:28:40+00:00Added an answer on June 14, 2026 at 9:28 am

    The PEP 8 standard way of handling that is to add a trailing underscore:

    • single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g.

    Tkinter.Toplevel(master, class_='ClassName')

    That’s a common workaround and won’t surprise anyone. You could implement that in your code like:

    def _createTag(tag, **attributes):
        out = "<" + tag
        if attributes:
            for attr, value in attributes.items():
                out += " " + attr.rstrip('_') + "=\"" + value + "\""
        out += ">"
        return out
    

    so that it automatically removes the extra underscore from any and all attributes. Then you could call:

    >>> h2('contents', class_='myh2tag', id_='contenttag')
    '<h2 class="myh2tag" id="contenttag">contents</h2>'
    

    and work around two separate Python namespace conflicts without handling either of them as a special case.

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

Sidebar

Related Questions

I have about 150 text files filled with character information. Each file contains two
Basically when I have a python file like: python-code.py and use: import (python-code) the
I have a Python script that reads through a text csv file and creates
I just started using/learning Python and have some questions. I have a text file
Im my Python file, I have imported the win32gui module like this: import win32gui
I have python file, for example, named blah.py, that I would like to have
I have a python file that I would like to set the SUID flag
I have a python file like this import urllib2 try: data = urllib2.urlopen('http:....').read() except
I'm trying to have python read some lines of text from a file and
I have a python file that holds a bunch of functions that I'm continually

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.