How to read static const variable in PyROOT?


I have a variable defined within a class like:

class EventConstants {
    static constexpr char* SIM_PARTICLES = (char*) "SimParticles";

I have included the EventConstants class in my ROOT dict but I do not see these types of variables defined anyplace when I look around in Python.

How can I read the values of these types of static const variables within my PyROOT session? Do I need some special arguments/declarations for these to be handled properly by the class dict?



Hi Jeremy,

did you give a try to?

import ROOT
class EventConstants {
    static const char* SIM_PARTICLES;
const char* EventConstants::SIM_PARTICLES = "SimParticles";

print ROOT.EventConstants.SIM_PARTICLES


I ended up just changing my constants to std strings instead of char*, and then I can see the constants fine in Python. So it doesn’t seem to interpret the C style strings correctly.

Anyways, this is a reasonable solution to me I think.




about correctly … “char*” in C++ is often used to mean “byte*” (and byte just having been voted down, that ambiguity will remain for some time). So, in the bindings, it is often conservatively treated as the latter b/c you can make a “char*” from a “byte*”, but not the other way around (any ‘\0’ in the data will terminate the string copy). You probably have more luck with “const char*”.