C++/Python function call
Stefan Behnel
stefan_ml at behnel.de
Tue Jun 29 15:20:02 EDT 2010
Rami Chowdhury, 29.06.2010 20:56:
> On Tuesday 29 June 2010 05:24:26 Zohair M. Abu Shaban wrote:
>>> From: rami.chowdhury at gmail.com
>>> On Monday 28 June 2010 12:46:13 Zohair M. Abu Shaban wrote:
>>>> I have this python function defined as:
>>>>
>>>> def set_time_at_next_pps(self, *args, **kwargs):
>>>> """set_time_at_next_pps(self, usrp2::time_spec_t time_spec)
>>>>
>>>> -> bool"""
>>>>
>>>> it was generated to do the same function as the c++:
"Generated" by what?
>>>> set_time_at_next_pps(usrp2::time_spec_t(0, 0))
>>>>
>>>> I am new to python and don't know hoe to use this python syntax.
>>>>
>>>> Any hint or help please?
>>>
>>> Can you give us a little more information? What do you need to use it
>>> for?
>>
>> I am using hardware that uses some libraries on Linux.
>>
>> def set_time_at_next_pps(*args, **kwargs):
>> """set_time_at_next_pps(self, usrp2::time_spec_t time_spec) ->
>> bool
>> """
>> return _usrp2.usrp2_base_set_time_at_next_pps(*args, **kwargs)
>>
>> This is actually a definition of a function in C++ transformed to python.
>> It receives a structure parameter and returns boolean the structure is
>> defined like this: in a library called libusrp2.so and the header file is
>> usrp2.h
>>
>> typedef struct time_spec{
>> uint32_t secs;
>> uint32_t ticks;
>> time_spec(void){
>> secs = ~0;
>> ticks = ~0;
>> }
>> time_spec(uint32_t new_secs, uint32_t new_ticks = 0){
>> secs = new_secs;
>> ticks = new_ticks;
>> }
>> } time_spec_t;
>>
>> in my python code I wrote:
>> zeroise=usrp2.time_spec_t(0,0)
>> self.$(id).set_time_at_next_pps(zeroise)
>>
>> The error Iam receiveing is :
>> zeroise=usrp2.time_spec_t(0,0)
>> AttributeError: 'module' object has no attribute 'time_spec_t'
What is "usrp2"? The "generated" module?
> Thank you for the details. Could you let me know how you're accessing the C++
> code? Are you using ctypes? Are you using a Python extension module that wraps
> the C++ code? Some other method?
These are the right questions.
>> MY PROBLEM THAT I NEED HELP FOR IS:
>> 1- Am I using the structure correctly?
>> 2- Am I invoking the python definition correctly?
>
> I'd guess not, since you're getting an error ;-)
Try "dir(usrp2)" or "help(usrp2)", that will tell you what the module provides.
If you're after wrapping the library yourself, take a look at ctypes and
Cython. Depending on the requirements, either of the two is a good choice.
Stefan
More information about the Python-list
mailing list