Reading in string arrays fail

I am having a trouble with retrieving a string array which is defined in a compiled C++ header file when I try to read from python. I am pretty new to python.

I searched the posts in the past for a solution, but couldn’t find any. If there was, I apologize, and I greatly appreciate if anyone can give me a link to that post to solve this problem…

Details are the followings…

I defined a namespace in my header file:

#ifndef TEST_hh
#define TEST_hh

namespace TEST{
  enum kTYPES
    {
      kFIRST,
      kSECOND,
      kMAX
    };
  
  const std::string kNAME[kMAX] =
    {
      "FIRST",
      "SECOND"
    };
};
#endif

I compiled the code with linking:

#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ namespace TEST;
#endif

The code compiles fine and creates “libTest.so”. When I try to access constants defined in the namespace “TEST” from python, I get the followings:

>>> from ROOT import gSystem
>>> gSystem.Load("libDCTest")
0
>>> from ROOT import TEST
>>> TEST.kFIRST
0
>>> TEST.kSECOND
1
>>> TEST.kMAX
2
>>> TEST.kNAME[1]
'\x01'
>>> TEST.kNAME[0]
'\r'

It seems the access to enumerator works just fine while the const string array element could not be retrieved by my intuitive, possibly very wrong, access method. Would anyone kindly suggest what I am doing wrong?

Thank you for all of your time.

Kazu

Kazu,

there is currently no support for C-style arrays of C++ types, as there is no such concept in python. The easiest thing to do is to use an std::vectorstd::string instead.

Cheers,
Wim

Dear Wim,

Thank you very much for your reply! That is helpful and I confidently request to make this into C++ container with C++ string.

Kazu