What the heck does I2C constructor asterisk mean?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
MicroGuy
Posts: 17
Joined: Sun Jan 17, 2021 8:31 pm

What the heck does I2C constructor asterisk mean?

Post by MicroGuy » Mon Apr 25, 2022 7:08 pm

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

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: What the heck does I2C constructor asterisk mean?

Post by Lobo-T » Mon Apr 25, 2022 9:16 pm

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.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: What the heck does I2C constructor asterisk mean?

Post by davef » Mon Apr 25, 2022 9:43 pm


User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: What the heck does I2C constructor asterisk mean?

Post by dhylands » Mon Apr 25, 2022 10:10 pm

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.

MicroGuy
Posts: 17
Joined: Sun Jan 17, 2021 8:31 pm

Re: What the heck does I2C constructor asterisk mean?

Post by MicroGuy » Mon Apr 25, 2022 11:04 pm

Thank you for the information, which I appreciate greatly. You have all saved me a lot of time! --Jon

Post Reply