Number of arguments for `micropython.schedule`

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
jphalip
Posts: 7
Joined: Thu Apr 29, 2021 2:22 am

Number of arguments for `micropython.schedule`

Post by jphalip » Thu Apr 29, 2021 2:38 am

Hi,

The signature of `micropython.schedule()` is `(func, arg)`, i.e. it takes the callback function and a single argument.

Is there a technical reason why only a single argument is supported?

I have a case where I'd like to pass multiple arguments. I resorted to grouping all the arguments into a tuple. That works but feels somewhat inelegant... :)

Code: Select all

micropython.schedule(func, (arg1, arg2, arg3))

def func(args):
    arg1, arg2, arg3 = args
    ...
Thanks you,

Julien

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Number of arguments for `micropython.schedule`

Post by pythoncoder » Thu Apr 29, 2021 9:43 am

I don't know the technical reason, but other workrounds are to pass an object as the arg, or to pass a bound method as the function.
Peter Hinch
Index to my micropython libraries.

Post Reply