Page 1 of 1

What the heck does I2C constructor asterisk mean?

Posted: Mon Apr 25, 2022 7:08 pm
by MicroGuy
In the documentation for the I2C constructors I find a statement such as:

classmachine.I2C(id=- 1, *, scl, sda, freq=400000)

What does the asterisk mean? I couldn't find an explanation and the documentation does not include one. All other information in this statement makes sense.

Thanks --Jon

Re: What the heck does I2C constructor asterisk mean?

Posted: Mon Apr 25, 2022 9:16 pm
by Lobo-T
I think it's something like that the parameters before the asterisk are mandatory, the ones after are optional and will have defaults.
There is probably a more formal explanation.

Re: What the heck does I2C constructor asterisk mean?

Posted: Mon Apr 25, 2022 9:43 pm
by davef

Re: What the heck does I2C constructor asterisk mean?

Posted: Mon Apr 25, 2022 10:10 pm
by dhylands
It's a python thing and not specific to MicroPython.

The formal definition can be found here: https://docs.python.org/3/reference/com ... efinitions

This is from the paragraph that starts "Function call semantics ..."
Parameters after “*” or “*identifier” are keyword-only parameters and may only be passed by keyword arguments.

Re: What the heck does I2C constructor asterisk mean?

Posted: Mon Apr 25, 2022 11:04 pm
by MicroGuy
Thank you for the information, which I appreciate greatly. You have all saved me a lot of time! --Jon