Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6785

MicroPython • Re: 2 arguments Bur given three

$
0
0
The fill method needs a color value only ...

pixels.fill(color)
But ... "TypeError: function takes 2 positional arguments" ... and that's just one argument !?!?!?

That's thrown me at times. The 'fill' method is probably defined via a 'NeoPixel' class, something like this -

Code:

class NeoPixel:  def fill(self, color):    ...
So, that is two positional arguments, but when called on an instantiated class, the 'pixels' variable here, that variable is moved into the 'self' of the definition -

Code:

pixels.fill(color)  |     :     |  |     :     `----.  `-----:---.      |        :   |      |  def fill(self, color):
That all makes sense, but a bit confusing when a mistake is made, it says it wants two when you really only have to provide one when calling.

Statistics: Posted by hippy — Sun Jul 14, 2024 6:37 pm



Viewing all articles
Browse latest Browse all 6785

Trending Articles