Need some help with the "Light" module in Python3 please


Python Beginner alert and long post warning :-o

I’m more or less a beginner with Python but I can follow the code and have used other programming languages.
I’ve managed to get working by copying it into my “~/flotilla-offline/flotilla-python/library/flotilla/” folder along with all the other .py files, and running it from there.

Having had success with that I decided to try and get the “Light” module working. Using as the basis for my new python light module.
I could see that first I probably needed to make some changes to and, as follows:

Extract from

from .rainbow import Rainbow
from .light import Light ←ADDED BY ME

VID = "16d0"
PID = “08c3”

LANG_REQUIRES = "Oh no! I need a {module_type} on channel {channel}"
LANG_FOUND = "Yay! I’ve found a {module_type} on channel {channel}"
LANG_READY = “Everything connected properly. Let’s go!”

class Client:
_module_handlers = {
‘dial’: Dial,
‘slider’: Slider,
‘motion’: Motion,
‘matrix’: Matrix,
‘number’: Number,
‘touch’: Touch,
‘light’: Light, ←UNCOMMENTED BY ME
# ‘colour’: Colour,
‘joystick’: Joystick,
‘motor’: Motor,
# ‘weather’: Weather,
‘rainbow’: Rainbow

My file ( This was based on the file)

from .module import Module

class Light(Module):
name = ‘light’

def light(self):
    if len( >= 0:
        return int([0])
        return 0

This is my “” program:

1 print(""“
2 This example requires the Light module,
3 you’ll find it in the mini kit.
4 Press Ctrl+C to exit.
5 “””)
7 import flotilla
8 import time
10 client = flotilla.Client(
11 requires={
12 ‘one’: flotilla.Light
13 })
15 def module_changed(channel, module):
16 light = client.first(flotilla.light)
18 while not client.ready:
19 pass
21 light = client.first(flotilla.Light)
23 try:
24 print(“OK”)
25 time.sleep(0.1)
26 except KeyboardInterrupt:
27 client.stop()

Before I started to write the code to display the output of the Light module I used the above for testing, just to see if it would get to line 24 .However, when I run it I get this error:

Traceback (most recent call last):
File “”, line 12, in <module>
‘one’: flotilla.Light
AttributeError: ‘module’ object has no attribute ‘Light’

I’ve tried various things but cannot overcome this error. I’m thinking that the problem might be line 7 ? I don’t know what this import is for or what it contains.

If anyone could spare some time to point me in the right direction I would really appreciate it.

TIA Steve


It’s tricky to see what you’re doing wrong, I suspect it might be more a case of it loading an unmodified library rather than anything you might have done wrong.

I’ll make these changes to the library and see what happens- I really should have sorted these out forever ago!

Update: Just changing and as you mentioned seemed to work:


Thanks for looking at this, I do appreciate it.

Sorry, but I’m not sure what you mean by that. Are you saying that my script “” should not show the error ?

Also, does it matter that all my files are in “~/flotilla-offline/flotilla-python/library/flotilla/” ?


The easiest way to make changes to the library, and to use it in general, is to install it by running:

sudo python3 develop

Which will link the files into the place where Python expects to see its libraries.

With that set up you should be able to run scripts anywhere, and “import flotilla” will always work.


I ran [quote=“gadgetoid, post:4, topic:1668”]
sudo python3 develop
[/quote]but unfortunately the error still occurs.


Today I have tried a different approach based on your first post.
I have used the new and files and modified with the changes needed to connect the Light module. So I have connected the Touch, Light and Rainbow modules and I don’t get any error messages. I can continue with my coding, thanks.

I think I’ve seen an anomaly in the code, the following code extract does not look correct, there are 2 channel one’s and no channel eight, but as a beginner I may be wrong:

    def channel_one(self):
        return self._modules[self._channel_names.index('one')]

    def channel_one(self):
        return self._modules[self._channel_names.index('one')]

    def channel_two(self):
        return self._modules[self._channel_names.index('two')]

    def channel_three(self):
        return self._modules[self._channel_names.index('three')]

    def channel_four(self):
        return self._modules[self._channel_names.index('four')]

    def channel_five(self):
        return self._modules[self._channel_names.index('five')]

    def channel_six(self):
        return self._modules[self._channel_names.index('six')]

    def channel_seven(self):
        return self._modules[self._channel_names.index('seven')]