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

**URL:** <https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668>\
**Category:** Flotilla\
**Created:** [January 25, 2016, 4:29pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668 "2016-01-25T16:29:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rc10b](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rc10b](https://forums.pimoroni.com/u/rc10b)\
**Post date:** [January 25, 2016, 4:29pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/1 "2016-01-25T16:29:56Z")

</div>

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 mini-kit.py 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 mini-kit.py as the basis for my new python light module.  
I could see that first I probably needed to make some changes to ` __init__.py` and light.py., as follows:

* * *

## Extract from ` __init__.py`

.  
.  
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 light.py file ( This was based on the touch.py file)

from .module import Module

class Light(Module):  
name = ‘light’

```
@property
def light(self):
    if len(self.data) >= 0:
        return int(self.data[0])
        return 0

```

* * *

## This is my “mini-kit\_light.py” 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 “”") 6 7 import flotilla 8 import time 9 10 client = flotilla.Client( 11 requires={ 12 ‘one’: flotilla.Light 13 }) 14 15 def module\_changed(channel, module): 16 light = client.first(flotilla.light) 17 18 while not client.ready: 19 pass 20 21 light = client.first(flotilla.Light) 22 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 “mini-kit\_light.py”, 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

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [January 25, 2016, 5:22pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/2 "2016-01-25T17:22:59Z")

</div>

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 **init**.py and [light.py](http://light.py) as you mentioned seemed to work: [https://github.com/pimoroni/flotilla-python/commits/master](https://github.com/pimoroni/flotilla-python/commits/master)

---

<div class="post-metadata">

**Author:** ![rc10b](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rc10b](https://forums.pimoroni.com/u/rc10b)\
**Post date:** [January 25, 2016, 7:12pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/3 "2016-01-25T19:12:24Z")

</div>

Thanks for looking at this, I do appreciate it.

> [@gadgetoid](#):
>
> seemed to work

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

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

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [January 25, 2016, 8:01pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/4 "2016-01-25T20:01:05Z")

</div>

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

```auto
sudo python3 setup.py 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.

---

<div class="post-metadata">

**Author:** ![rc10b](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rc10b](https://forums.pimoroni.com/u/rc10b)\
**Post date:** [January 25, 2016, 8:17pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/5 "2016-01-25T20:17:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rc10b](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rc10b](https://forums.pimoroni.com/u/rc10b)\
**Post date:** [January 26, 2016, 3:45pm UTC](https://forums.pimoroni.com/t/need-some-help-with-the-light-module-in-python3-please/1668/6 "2016-01-26T15:45:23Z")

</div>

Today I have tried a different approach based on your first post.  
I have used the new ` __init__.py` and [light.py](http://light.py) files and modified [mini-kit.py](http://mini-kit.py) 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 ` __init__.py` 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:

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

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

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

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

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

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

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

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