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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:27:05+00:00 2026-05-20T01:27:05+00:00

I have a subclass of the ‘ str ‘ object and I need to

  • 0

I have a subclass of the ‘str‘ object and I need to apply it to the application domain. Since the application is full of string literal and str() casts it will take a long time to change all of them to the custom string class. I know it is possible to override ‘str()’ but I’m not sure about string literals.

I know it is not a good idea but the application requires it. Is it possible to do it in Python? And if not, does it require me to modify ‘stringlib‘ which is the C implementation of the ‘str‘ object?

I’m also aware of the fact that modifying the parser to make the application run is considered to be a very bad programming practice. Can this be achieved via an extension rather than a parser modification?

  • 1 1 Answer
  • 1 View
  • 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-20T01:27:05+00:00Added an answer on May 20, 2026 at 1:27 am

    You cannot modify built-in types, e.g. you cannot add new attributes at runtime1:

    >>> setattr(str, "hello", lambda: "Hello custom str!")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: can't set attributes of built-in/extension type 'str'
    

    I would try to parse all literal strings and replace them with the constructor of your custom string subclass. This is first and foremost:

    • explicit, which makes it easier for you and other to remember, that this string is different.

    Typically i18n libraries have some kind of string literal detection routines for code, which could come in handy during detection. Once these strings are gathered, it’s more or less just replace.


    1 This is also one reason, python isn’t as flexible as ruby. You can’t just write test libraries, that monkey patch core classes and add methods like should_equal to every object in the runtime. Here is an entertaining tech talk about these nuances and their consequencies: http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-death.html

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

Sidebar

Related Questions

I have a subclass of UIImageView that I need to know when is touched.
I have a subclass of wxHtmlListBox called TestClass, but I get the error: /usr/include/wx-2.8/wx/string.h:682:0
I have subclass of NSObject having 70 properties, i need to observe change in
I have a subclass of UIViewController that is responsible for a single UIWebView. Since
I have a subclass of UIView that's instantiated in a XIB file. I need
I have subclass of UINavigationBar . @interface MyNavigationBar : UINavigationBar Made some changes and
HI All. I have subclass of UIScrollView. IN this class I have added some
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a subclass of JLabel that forms a component of my GUI. I
I have a subclass that calls a method from a superclass. The method in

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.