通过 SWIG 从 Python 访问 UtcTimeStamp
我想这是一个 python 与 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>
如何从中提取数据?
更新:
我找到了 UTCTimeStamp 类,该类派生自 DateTime 结构 - 它是开源 QuickFix 包的一部分。
但是我仍然不知道如何访问数据。 DateTime 有简单的 getter 函数,例如 getYear() - 但是,如何访问它们?
I guess this is a python vs SWIG question more than anything else...
I'm using a C++ package with SWIG Python bindings.
One of the objects I receive is a UTC time stamp from which I'm trying to extract the time stamp.
The object has the following characteristics:
>>> 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>
How do I extract the data out of it?
UPDATE:
I've found the UTCTimeStamp class which is derived from a DateTime struct - it is part of the open source QuickFix package.
However I still don't know how to access the data. DateTime has simple getter functions such as getYear() - however, how do I access them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在时间字段上使用
qfTimeField.getValue()
,而是使用qfTimeField.getString()
,然后仅使用strptime()
结果字符串。例如:Instead of using
qfTimeField.getValue()
on the time field, useqfTimeField.getString()
, and then juststrptime()
the resulting string. For example:您尝试过 obj.getYear() 吗?从文档中可以看出,
UTCTimeStamp
派生自DateTime
,因此您应该能够访问父类的方法。如果这不起作用,那么如果您执行 newobj = obj.next() ,您会得到什么样的对象?您是否尝试过
print obj.__doc__?
编辑:来自 http ://www.swig.org/Doc1.3/Python.html#Python_nn27a:
因此,您需要将其传递给可以采用
DateTime
的 C++ 函数的包装器。我不知道具体是什么,因为我不知道你在包装什么。在本例中,即 http://www.quickfixengine.org/quickfix/doc /html/struct_f_i_x_1_1_utc_time_stamp_convertor.html。我相信,虽然我无法测试这一点,但您可以这样称呼它:
Did you try
obj.getYear()
? It appears from the documentation thatUTCTimeStamp
derives fromDateTime
, so you should be able to access methods of the parent class.If that doesn't work, what kind of object do you get if you do
newobj = obj.next()
? Did you tryprint obj.__doc__?
Edit: from http://www.swig.org/Doc1.3/Python.html#Python_nn27a:
So you need to pass it to a wrapper for a C++ function that can take a
DateTime
. I don't know specifically what that is, as I don't know what you're wrapping.In this case, that is http://www.quickfixengine.org/quickfix/doc/html/struct_f_i_x_1_1_utc_time_stamp_convertor.html. I believe, although I can't test this, that you call it with: