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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:12:10+00:00 2026-05-16T15:12:10+00:00

(All in ActivePython 3.1.2) I tried to change the class (rather than instance) attributes.

  • 0

(All in ActivePython 3.1.2)

I tried to change the class (rather than instance) attributes. The __dict__ of the metaclass seemed like the perfect solution. But when I tried to modify, I got:

TypeError: ‘dict_proxy’ object does
not support item assignment

Why, and what can I do about it?

EDIT

I’m adding attributes inside the class definition.

setattr doesn’t work because the class is not yet built, and hence I can’t refer to it yet (or at least I don’t know how).

The traditional assignment doesn’t work because I’m adding a large number of attributes, whose names are determined by a certain rule (so I can’t just type them out).

In other words, suppose I want class A to have attributes A.a001 through A.a999; and all of them have to be defined before it’s fully built (since otherwise SQLAlchemy won’t instrument it properly).

Note also that I made a typo in the original title: it’s __dict__ of a regular class, not a metaclass, that I wanted to modify.

  • 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-16T15:12:11+00:00Added an answer on May 16, 2026 at 3:12 pm

    The creation of a large number of attributes following some rule smells like something is seriously wrong. I’d go back and see if there isn’t a better way of doing that.

    Having said there here is “Evil Code” (but it’ll work, I think)

    class A:
        locals()['alpha'] = 1
    
    print A.alpha
    

    This works because while the class is being defined there is a dictionary that tracks the local variables you are definining. These local variables eventually become the class attributes. Be careful with locals as it won’t necessarily act “correctly.” You aren’t really supposed to be modifying locals, but it does seem to work when I tried it.

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

Sidebar

Related Questions

All I want is to be able to change the color of a bullet
All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of
All thread create methods like pthread_create() or CreateThread() in Windows expect the caller to
All the CSS attributes apply to the <input type='file'/> don't work on FF, but
In Python, None evaluates to less than zero? ActivePython 2.7.2.5 (ActiveState Software Inc.) based
All, Say I have the following divs: <div id=rotate_container> <div class=reviews id=item1>This is item
All my classes are derived from this T class: public abstract class Problem<T, TResult>
All the articles I've found via google are either obsolete or contradict one another.
All the recent VisualSVN Server posts made me want to check it out. I
All front-end developers know the pain of coding for Firefox, then viewing our then

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.