How to create a Python function which accepts a list as an argument variable? #10877
Unanswered
synapticonashaikh
asked this question in
Libraries & Drivers
Replies: 1 comment 9 replies
-
Something like this. STATIC mp_obj_t COE_MyFunction(mp_obj_t arg_in) {
mp_int_t first = mp_obj_get_int(mp_obj_subscr(arg_in, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL)) + 5; //should interpret first element as integer
mp_int_t first = mp_obj_get_int(mp_obj_subscr(arg_in, MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_SENTINEL)) + 2; //should interpret second element as integer
// assuming data is a UTF-8 string. if it is arbitrary bytes, use buffer protocol instead
const char *third mp_obj_str_get_str(mp_obj_subscr(arg_in, MP_OBJ_NEW_SMALL_INT(2), MP_OBJ_SENTINEL)); //should interpret third element as int8_t/ uint8_t or byte array
mp_float_t fourth = mp_obj_get_float(mp_obj_subscr(arg_in, MP_OBJ_NEW_SMALL_INT(3), MP_OBJ_SENTINEL)) * MICROPY_FLOAT_CONST(10.4); //should interpret fourth element as float
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(COE_MyFunction_obj, COE_MyFunction); Another option is to unpack the list in Python and use 4 args. COE.MyFunction(*List_Variable) |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
I'm developing a module wherein I want to add some functions which take the list as an argument variable, and later on, I can process it. Please check the pseudo-code for more clarification.
Now, I need help with the syntactical flow and how to process this list in my function.
Please let me know if anyone knows how to achieve this task. Any support, hint or suggestion is highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions