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

  • Home
  • SEARCH
  • 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 7515757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:54:39+00:00 2026-05-30T00:54:39+00:00

I subclassed from StringIO to create a MockFile-class. There should be an Attribute name

  • 0

I subclassed from StringIO to create a MockFile-class. There should be an Attribute “name” in the derived class, but creating this Attribute throws an AttributeError.

Puzzled i did a __dict__ lookup and found that there was already a name-key. Iterating through the __mro__ i found a property named ‘name‘, obviously read-only in theio.TextIOWrapper class.

So i have basically two Questions:

  1. for what is this ‘name’ property intended
  2. is it safe to overwrite it with a settattr assignment?

The example-code for completness:

class MockFile(StringIO): 
    def __init__(self, name, buffer_ = None):
        super(MockFile, self).__init__(buffer_)
        self.name = name     
>>> mfile = MockFile('stringio.tmp', u'#MockFile')

leads to:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in __init__
AttributeError: can't set attribute
  • 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-30T00:54:40+00:00Added an answer on May 30, 2026 at 12:54 am

    The name property of io.StringIO in Python 2.6 comes from the class hierarchy in the io module. It’s a somewhat complex setup with both inheritance and composition, and the name property is used to propagate names from underlying objects to the various wrappers and specializations. The actual property on io.StringIO is gone in Python 2.7 and later, though, so you should be fine to shadow it in your subclass.

    You can’t use setattr() to set the property any more than actual assignment — settattr() and attribute assignment both work the same way. The nature of property prevents you from shadowing the baseclass property with an instance attribute (without doing more.) You can, however, define a property of your own with the same name, or trick Python into not seeing the property in the first place:

    class MockFile(StringIO):
        name = None
        def __init__(self, name, buffer_ = None):
            super(MockFile, self).__init__(buffer_)
            self.name = name     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic data class that is subclassed from NSObject. I declare
I have a basic class that derived subclasses inherit from, it carries the basic
I have a Card class subclassed from UIView and a Deck class from NSObject.
I'm looking to have a class (subclassed from threading.Thread) that is initialised and started
I have a class Hero, subclassed from CCSpriteBatchNode (cocos2d): @interface Hero : CCSpriteBatchNode {...}
I'm a bit lost here. I have a class subclassed from UIView called BalloonGuy.
I have a container class (subclassed from list) where I have overridden the geattr
I have Admin User extended/subclassed by Teacher class. How to prevent Teachers from seeing
I have a class inherited from UITableViewController and this is also the root class.
I have a custom ListView class (subclassed from ListView) and I need it to

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.