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

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Add the following attribute the action (post) in the controller… May 16, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer Unfortunately, SQLAlchemy doesn't allow you to subclass Base without a… May 16, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer Update 5/14/2015 Commenters point out that I'm mostly wrong. If… May 16, 2026 at 3:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a small piece of code that depends on many static libraries (a_1-a_n).
I have a public facing hobby site that gets about 3000 unique visitors a
I have used Flex for about a year before deciding that I would rather
Before I found out about that adb shell doesn't have the permission to do
I'm writing a small program to read in a csv with a variable number
Small preamble. I was good java developer on 1.4 jdk. After it I have
I recently asked a question about using XSL/t for creating a site layout and
I have written a small program using Borland's C++ builder, and along the way,
I have a relatively small xml file <g> <page no=1 href=page1.xml > <pic src=20100101001.jpg>1</pic>
I have a variety of small C# winforms applications (though this should apply equally

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.