discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non-hacky method to take list of keys as parameter?


From: Marcus Müller
Subject: Re: Non-hacky method to take list of keys as parameter?
Date: Fri, 16 Jul 2021 12:07:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

No problem at all, Anton :)

The conversions are basically: if it's a list of a basic type, it can be 
converted to a
C++ std::vector<that type>.
From the top of my head, we don't have a lot of methods in GNU Radio where we 
expose a
std::vector<std::string> parameter to Python, but we do have some where we 
return a C++
vector of strings and it gets converted to a Python `list` of `str`. All that 
should be
necessary for that is to `#include <pybind11/stl.h>` in
python/yourmodule/bindings/yourblock_python.cc

Best regards,
Marcus

On 16.07.21 00:08, Anton Ottosson wrote:
> Oh, sorry! I meant Marcus, of course, not "Amrcus".
> 
> 
> Best,
> 
> Anton
> 
> ------------------------------------------------------------------------------------------
> *From:* Anton Ottosson
> *Sent:* Friday, July 16, 2021 12:07:47 AM
> *To:* discuss-gnuradio@gnu.org
> *Subject:* Re: Non-hacky method to take list of keys as parameter?
>  
> 
> Hi Amrcus,
> Your first example would be ideal, but I seem to remember trying that and 
> having issues
> with it, probably due to the implicit type conversion from Python to C++. I 
> will try
> again, but is there anywhere one can look up what the conversions are?
> 
> 
> Best regards,
> 
> Anton
> 
> ------------------------------------------------------------------------------------------
> *From:* Marcus Müller <mmueller@gnuradio.org>
> *Sent:* Thursday, July 15, 2021 11:54:00 PM
> *To:* discuss-gnuradio@gnu.org
> *Cc:* Anton Ottosson
> *Subject:* Re: Non-hacky method to take list of keys as parameter?
>  
> Just use `dtype: raw` in the YAML file; then anything that's valid python 
> goes!
> 
> For example `["key1", "key2"]`,
>  but also other things like dicts, `{ "key1": 42, "key2": 1337 }`.
> 
> Best regards,
> Marcus
> 
> On 15.07.21 06:58, Anton Ottosson wrote:
>> Hi,
>> 
>> I'm writing a block for an OOT module and I would like to take a list of 
>> keys as one of
>> the parameters. They will be used to select entries in a pmt dictionary. I 
>> first tried to
>> use std::vector<std::string> as the parameter type, but there doesn't seem 
>> to exist any
>> corresponding string_vector dtype to use in the YAML file
>> (https://wiki.gnuradio.org/index.php/YAML_GRC
>> <https://wiki.gnuradio.org/index.php/YAML_GRC
> <https://wiki.gnuradio.org/index.php/YAML_GRC>>). I then switched over to pmt 
> arguments and
>> managed to get it to work, but it is very ugly and hacky. This is the kind 
>> of thing I have
>> to enter into the parameter field on the block:
>> 
>> 
>> pmt.list2(pmt.intern("key1"), pmt.intern("key2"))
>> 
>> 
>> Is there a better way? Is there a block that does something similar that I 
>> can take a look
>> at? Best I could find was PDU Filter, but it only takes a single key, not a 
>> list.
>> 
>> 
>> Best regards,
>> 
>> Anton
>> 

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]