4

According to Python documentation, implementing a class in C for Python can be roughly divided into three steps:

  1. defining the Object (the data impl)
  2. defining the Type (the behavior wrapper)
  3. defining concrete behaviors, and set them into corresponding tp_xx slots

For new function, init function, instance members, attributes, and even dealloc, all of them can be found a slot in PyTypeObject declaration, like tp_new, tp_init, tp_members, tp_methods and tp_dealloc. But there is not a slot like tp_statics.

Where should I declare the static variables and where should I set them up? I searched for the internet but got nothing. Could anyone give me a clue about this?

2 Answers 2

1

Maybe you should check out this question.

There is no static keyword in Python, class attributes are stored in class.__dict__.

Sign up to request clarification or add additional context in comments.

Comments

0

@avram has mentioned an answer which solved my problem.
But for anyone who found that your static attributes does not get updated after modification, you may check PyType_Modified function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.