我想这是一个python vs SWIG的问题。。。在
我使用一个带有SWIG Python绑定的C++包。 我收到的对象之一是UTC时间戳,我正试图从中提取时间戳。在
该对象具有以下特征:
>>> print type(obj)
<type 'SwigPyObject'>
>>> print dir(obj)
['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__hex__', '__init__', '__int__', '__le__', '__long__', '__lt__', '__ne__', '__new__', '__oct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'acquire', 'append', 'disown', 'next', 'own']
>>> print obj
<Swig Object of type 'UtcTimeStamp *' at 0x0379F320>
如何从中提取数据?在
更新:
我找到了从DateTime结构派生的UTCTimeStamp类,它是开源QuickFix包的一部分。在
但是我还是不知道如何访问数据。DateTime有一些简单的getter函数,比如getYear()——但是,如何访问它们呢?在
你试过
obj.getYear()
?从文档中可以看出,UTCTimeStamp
是从DateTime
派生的,因此您应该能够访问父类的方法。在如果这不起作用,你得到什么样的物体?你试过
print obj.__doc__?
编辑:来自http://www.swig.org/Doc1.3/Python.html#Python_nn27a:
因此,您需要将其传递给C++函数的包装器,该函数可以使用^ {< CD3>}。我不知道具体是什么,因为我不知道你在包装什么。在
在本例中,即http://www.quickfixengine.org/quickfix/doc/html/struct_f_i_x_1_1_utc_time_stamp_convertor.html。我相信,虽然我无法测试,但你称之为:
不要在时间字段上使用
qfTimeField.getValue()
,而是使用qfTimeField.getString()
,然后只使用strptime()
得到的字符串。例如:相关问题 更多 >
编程相关推荐