How do you save a Python script?


#1

I have been getting pretty comfortable writing simple scripts in Python 3 for my Blinkt! and have been saving the shells as .py files just like the examples that are in the blinkt! folder. the issue is that when i click on them, the execute option does not pop up, instead it just opens it as a word file. is there a reason a script would work in the shell, but not open as a script when i save it? honestly all i really want at this point is for a solid color to save as an executable script. i know i have to be missing something. this is

This is what i am trying to make work.

from blinkt import set_pixel, set_brightness, show, clear
set_brightness(0.1)
clear()

# set all pixels to RED
for i in range(8):
    set_pixel(i, 255, 0, 0)

show()

Thanks again!


#2

I just right click, open with idle3, then do the run. I’ve never tried to just run them via a double click, if that’s even possible? Even in terminal I do a “python3 /myfile.py.”


#3

so where i am running into trouble is i am trying to run a cronetab to turn the LED’s on at boot so

crontab -e

@reboot python /home/pi/Pimoroni/blinkt/examples/mypython3file.py &

it will load with the included examples like

@reboot python /home/pi/Pimoroni/blinkt/examples/rainbow.py &

but not with the files i make.


#4

What happens if you open the terminal and attempt to run your Python file?

ie:

python /home/pi/Pimoroni/blinkt/examples/mypython3file.py

#5

May also want to try using @reboot python3 instead of just python. Using just “python” runs your file in python 2, not 3. I’ve had on occasion, python files that work fine in one but not the other.