Details
-
Type:
Bug
-
Status: Done
-
Resolution: Done
-
Fix Version/s: None
-
Component/s: ts_middleware
-
Story Points:2
-
Epic Link:
-
Sprint:TSSW Sprint - Jan 21 - Feb 02
-
Team:Telescope and Site
Description
I have a Data struct that looks like this
.h
class AckCmd
{
public:
SALData_ackcmdC ackData;
AckCmd(int ack, int error, std::string result);
};
.cpp
AckCmd::AckCmd(int ack, int error, std::string result)
{
ackData.ack = ack;
ackData.error = error;
ackData.result = result;
}
I then am binding it as follows
py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())
.def(py::init<int, int, const std::string &>())
;
I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error.
I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object.
However, when I enter the following within a python shell
>>> import SALPY_Library
>>> myAck = SALPY_Library.AckCmd( 1, 2, "myack")
>>> print(myAck.ack)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack'
The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct.
>>> myAck.__
myAck._class( myAck.doc myAck.getattribute( myAck.init_subclass( myAck.ne( myAck.repr( myAck.subclasshook_(
myAck._delattr( myAck.eq( myAck.gt( myAck.le( myAck.new( myAck.setattr_(
myAck._dict myAck.format( myAck.hash( myAck.lt( myAck.reduce( myAck.sizeof_(
myAck._dir( myAck.ge( myAck.init( myAck.module myAck.reduce_ex( myAck.str_(
Attachments
Issue Links
- relates to
-
DM-17747 Russell Pybind 11 hack session
- Done
The following email is a draft of what I plan on sending to Pim.
Hi Pim,
Dave tells me you have worked with Pybind11 and I was wondering if you could me with a problem I am having.
I have a Data struct that looks like this
.h
class AckCmd
{
public:
SALData_ackcmdC ackData;
AckCmd(int ack, int error, std::string result);
};
.cpp
AckCmd::AckCmd(int ack, int error, std::string result)
{
ackData.ack = ack;
ackData.error = error;
ackData.result = result;
}
I then am binding it as follows
py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())
.def(py::init<int, int, const std::string &>())
;
I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error.
I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object.
However, when I enter the following within a python shell
>>> import SALPY_Library
>>> myAck = SALPY_Library.AckCmd( 1, 2, "myack")
>>> print(myAck.ack)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack'
The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct.
>>> myAck.__
myAck._class( myAck.doc myAck.getattribute( myAck.init_subclass( myAck.ne( myAck.repr( myAck.subclasshook_(
myAck._delattr( myAck.eq( myAck.gt( myAck.le( myAck.new( myAck.setattr_(
myAck._dict myAck.format( myAck.hash( myAck.lt( myAck.reduce( myAck.sizeof_(
myAck._dir( myAck.ge( myAck.init( myAck.module myAck.reduce_ex( myAck.str_(
Would you be able to help with binding these attributes correctly?