[Microbit-Python] Image class constructors question

Radomir Dopieralski microbit at sheep.art.pl
Wed May 11 18:20:14 EDT 2016


I didn't realize Python supports mutliple dispatch based on types like
that! Looks almost like it was designed by a C++ programmer :)

On Wed, 11 May 2016 22:59:08 +0100
Damien George <damien.p.george at gmail.com> wrote:

> The docs are wrong.  There are 5 constructors:
> 
> Image() - return the blank image
> Image(chr) - return an image with the character rendered to the image
> Image(string) - return an image described by the string (eg
> 01110:00000 etc) Image(width, height) - create a blank image of given
> size Image(width, height, buffer) - create an image of the given size,
> initialsed by the buffer
> 
> 
> 
> On Fri, May 6, 2016 at 6:14 PM, Joe Glancy <joe.t.glancy at gmail.com>
> wrote:
> > In the documentation, the image class defines the two following
> > constructors (or their equivalent):
> >
> > classmicrobit.Image(string) classmicrobit.Image(width=None,
> > height=None, buffer=None)
> >
> > Does that not mean that I could initialise a new class:
> >
> >     img = microbit.Image(foo_variable)
> >
> > And it could be interpreted as either giving a string or giving a
> > width? Or does MicroPython have something that stops this (like
> > checking the type of `foo_variable`)? Quote the documentation:
> >
> > Optionally buffer can be an array of width``×``height integers in
> > range 0-9 to initialize the image.
> >
> > So are width and height optional too, or not (so shouldn't have the
> > `=None`)? Or can I choose one or the other?
> >
> > _______________________________________________
> > Microbit mailing list
> > Microbit at python.org
> > https://mail.python.org/mailman/listinfo/microbit
> >
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit



-- 
Radomir Dopieralski

-- 
Radomir Dopieralski


More information about the Microbit mailing list