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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:30:14+00:00 2026-06-04T13:30:14+00:00

How can you access class values from within the top level class scope? What

  • 0

How can you access class values from within the top level class scope? What I mean by that is, how do you do something like:

class FooClass(object):
    zeroith_base = __bases__[0]
    .
    .
    .

What I’m specifically trying to do in this case is derive the metaclasses of all base classes to dynamically generate a metaclass that subclasses all the base classes’ metaclasses to get past metclass conflict problems. I found http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/, and while all the concepts make sense to me, the actual code of the recipe is just beyond my ability to follow it. I don’t want to use code I can’t understand though, so instead, I tried to implement my own, more rudimentary system, but I’m stuck at square one trying to inspect the class object during creation.

  • 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-04T13:30:15+00:00Added an answer on June 4, 2026 at 1:30 pm

    You cannot inspect a class prior to its creation, and it has not yet been created yet until the suite of statements, or class body, have finished executing. The first time you have access to this information would be in the MetaClass.__new__ method of the class creating the class in question, or the execution of the thing creating the class in question, which technically need not be a meta-class or a class at all (as in the example below).

    Here is a very rough prototype that probably does not work in all cases, but works in the simple case, and is probably easier to follow than the recipe.

    def meta_class_synthesize(name, bases, attrmap):
        seen = set()
        seen_add = seen.add
        metas = [type(base) for base in bases]
        metas = tuple([
            meta for meta in metas
            if meta is not type and meta not in seen and not seen_add(meta)])
        if not metas:
            return type(name, bases, attrmap)
        elif len(metas) == 1:
            return metas[0](name, bases, attrmap)
        newmeta_name = "__".join(meta.__name__ for meta in metas)
        newmeta = type(newmeta_name, metas, {})
        return newmeta(name, bases, attrmap)
    
    class M_A(type):
        pass
    
    class M_B(type):
        pass
    
    class A:
        __metaclass__ = M_A
    
    class B:
        __metaclass__ = M_B
    
    class C(A, B):
        __metaclass__ = meta_class_synthesize
    
    
    print type(C)  # prints "<class '__main__.M_A__M_B'>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a database class but can't access the method from within: class
How can I access a variable in one public class from another public class
How can I access metadata (dataannotations attributes) in my asp.net mvc model class from
To what extent can a class protect one of it's attributes from outside access?
How can hibernate can access a private field/method of a java class , for
Protected Means, we can access this member only in a deriving class, and internal
How can I access a static variable in a separate class in PHP? Is
I am trying to access child class variables in parent class..can u suggest me
How can I override class attribute access in python? P.S. Is there a way
I can access my variable stored in a backing bean from my JSF2 page,

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.