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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:48:04+00:00 2026-05-23T16:48:04+00:00

So, the python docs for writing extension says this: We want to expose our

  • 0

So, the python docs for writing extension says this:

“We want to expose our instance
variables as attributes. There are a
number of ways to do that. The
simplest way is to define member
definitions:

static PyMemberDef Noddy_members[] = {
    {"first", T_OBJECT_EX, offsetof(Noddy, first), 0,
     "first name"},
    {"last", T_OBJECT_EX, offsetof(Noddy, last), 0,
     "last name"},
    {"number", T_INT, offsetof(Noddy, number), 0,
     "noddy number"},
    {NULL}  /* Sentinel */
};

and put the definitions in the
tp_members slot:

Noddy_members,             /* tp_members */"

However, we have already put the instance variables in the Noddy struct:

 typedef struct {
    PyObject_HEAD
    PyObject *first;
    PyObject *last;
    int number;
} Noddy;

so my question is that why we put them in both places. My impression is that, that is because we want both type and the instance to have them so that we preserve the types values once the instance get updated. But If thats the case, how does the instance value get updated if we change the class attribute? like this:

>>> class foo(object): x = 4
...
>>> f = foo()
>>> f.x
4
>>> foo.x = 5
>>> f.x
5
  • 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-23T16:48:04+00:00Added an answer on May 23, 2026 at 4:48 pm

    Ok So I did my research and yes instance variables and attributes are different and thats because classes instances and classes have separate dictionaries. As said in the documentation::

    A class instance is created by calling
    a class object (see above). A class
    instance has a namespace implemented
    as a dictionary which is the first
    place in which attribute references
    are searched. When an attribute is not
    found there, and the instance’s class
    has an attribute by that name, the
    search continues with the class
    attributes.

    So basically the Noddy struct holds the instance variables. The Noddy_members holds the attributes. Furthermore:

    Attribute assignments and deletions
    update the instance’s dictionary,
    never a class’s dictionary. If the
    class has a setattr() or
    delattr() method, this is called instead of updating the instance
    dictionary directly.

    Also:

    If a class attribute is found that is
    a user-defined function object or an
    unbound user-defined method object
    whose associated class is the class
    (call it C) of the instance for which
    the attribute reference was initiated
    or one of its bases, it is transformed
    into a bound user-defined method
    object whose im_class attribute is C
    and whose im_self attribute is the
    instance. Static method and class
    method objects are also transformed,
    as if they had been retrieved from
    class C; see above under “Classes”.
    See section Implementing Descriptors
    for another way in which attributes of
    a class retrieved via its instances
    may differ from the objects actually
    stored in the class’s dict. If no
    class attribute is found, and the
    object’s class has a getattr()
    method, that is called to satisfy the
    lookup.

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

Sidebar

Related Questions

Python docs mention this word a lot and I want to know what it
http://docs.python.org/3.0/whatsnew/3.0.html says it lists whats new , but in my opinion, it only lists
I'm speaking of this module: http://docs.python.org/library/operator.html From the article: The operator module exports a
The python docs gives this code as the reverse operation of zip: >>> x2,
I'm in the process of writing a python script, and I want to find
From Python docs: sys.excepthook(type, value, traceback) This function prints out a given traceback and
I have one question about sys.setrecursionlimit() From the python docs this function: Set the
The Python docs say: re.MULTILINE: When specified, the pattern character '^' matches at the
http://code.google.com/appengine/docs/python/tools/uploadingdata.html is not clearly understand. Where i should call the bulkloader.py or appcfg.py? Should
In Python 2.6, a new timeout parameter was added to the httplib.HTTPConnection class: http://docs.python.org/library/httplib.html#httplib.HTTPConnection

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.