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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:24:30+00:00 2026-05-15T19:24:30+00:00

I have a small question about static variable and TypeObjects. I use the API

  • 0

I have a small question about static variable and TypeObjects.
I use the API C to wrap a c++ object (let’s call it Acpp) that has a static variable called x.
Let’s call my TypeObject A_Object :

typedef struct {
  PyObject_HEAD
  Acpp* a;
} A_Object;

The TypeObject is attached to my python module “myMod” as “A”. I have defined getter and setters (tp_getset) so that I can access and modify the static variable of Acpp from python :

>>> import myMod
>>> myA1 = myMod.A(some args...)
>>> myA1.x = 34 # using the setter to set the static variable of Acpp
>>> myA2 = myMod.A(some other args...)
>>> print myA2.x
34
>>> # Ok it works !

This solution works but it’s not really “clean”. I would like to access the static variable in python by using the TypeObject and not the instances :

>>> import myMod
>>> myMod.A.x = 34 # what I wish...

Does anybody have an idea to help me ?

Thanks in advance.

  • 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-15T19:24:30+00:00Added an answer on May 15, 2026 at 7:24 pm

    Essentially, what you’re trying to do is define a “static property”. That is, you want a function to be called when you get/set an attribute of the class.

    With that in mind, you might find this thread interesting. It only talks about Python-level solutions to this problem, not C extension types, but it covers the basic principles.

    To implement the solution proposed in that thread for a C extension type, I think you’d have to initialize tp_dict and add to it an entry for “x” whose value is an object that implements __get__ appropriately.

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

Sidebar

Related Questions

I have a question about technology or methodology out there that I can use
I have a small question about the Core Bluetooth framework. I know Core Bluetooth
I have a question about a small problem I am having in Magento. When
I'm using BerkeleyDB to develop a small app. And I have a question about
hello I have a small question in objective-C memory management. I know that if
I have small question about pdp-11(simulator), I have this command (it begins from the
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
I have a small question about structures with the LayoutKind.Explicit attribute set. I declared
I have a small question about threads. On Unix systems, we have nice ,
I am new to Shell script. Just have a small question about some script

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.