question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to define static class variable?

See original GitHub issue

How to define static class variable and constant in Cython just as following code’s semantic?

1:  cdef class Car:
2:      cdef int battery=100 # Instance variable
3:      cdef static int total_car_count = 0 # Static variable shared among classes.
4:      cdef const int WHEEL_COUNT = 4 # Constant of class Car.

As far as I know, the syntax of line 3 and line4 is not supported by Cython… But is there any syntax to define static and constant variables in Cython? If not, is there any way to mimic the semantics of static and constant variables?

Thanks

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
da-woodscommented, Jul 14, 2022

Did anything change?

No

0reactions
FilipDeptacommented, Jul 18, 2022

Ok, thank you. In my case, the class variable will be used in heavy number crunching, so a better option is to define it as a global C variable, I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Static Members of a C++ Class - Tutorialspoint
We can define class members static using static keyword. When we declare a member of a class as static it means no matter...
Read more >
Initialize static variables in C++ class? - Stack Overflow
Static member variables always hold the same value for any instance of your class: if you change a static variable of one object,...
Read more >
C++ Tutorial: Static Variables and Static Class Members - 2020
Variables defined outside a function or by using the keyword static have static storage duration. They persist for the entire running time of...
Read more >
How to create and use static class variables in Python
The variables that are defined at the class level are static variables. If we want to create a variable whose value should not...
Read more >
Static Classes and Static Class Members - C# guide
It is more typical to declare a non-static class with some static members, than to declare an entire class as static. Two common...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found