Subj : Re: Python To : Nightfox From : Mortifis Date : Mon Dec 10 2018 10:35 am > Re: Python > By: Mortifis to All on Sun Dec 09 2018 01:40 pm > Mo> Anyone into Python? I have a few questions relating to nested loops > I've done a bit of Python for work. Seems Python is very finicky about use of proper indentation :/ I am (trying) to code some random light sequences for use with my Raspberry Pi, mostly works, however, when I try to set a while ... for ... try while ... blah blah blah it complains about indentation. when I remove the first x = 0 ... while x < cycle: x = x + 1 it seems to work correctly. here is my spaghetti code: #!/usr/bin/python import RPi.GPIO as GPIO import time import random import mutagen.mp3 import sys GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # init list with pin numbers seq0 = [2, 3, 4, 17, 27, 22, 10, 9] # RPI GPIO PINS seq1 = [3, 17, 22, 9] seq2 = [2, 4, 27, 10] seq3 = [2, 9, 3, 10, 4, 22, 17, 27, 27, 17, 22, 4, 10, 3, 9, 2] from random import randint rand = random.randint(0, 3) mP3 = sys.argv[1] from mutagen.mp3 import MP3 audio = MP3(mP3) cycle = int(audio.info.length) print ' Playing ', mP3, ' for ', cycle, 'seconds' if mP3 == "letitgo.mp3": rand = 1 # speeds timing up SleepTimeS = 0.2 SleepTimeL = 0.1 else: SleepTimeS = 1.2 # normal speed SleepTimeL = 0.2 if rand == 0: seq = seq0 if rand == 1: seq = seq1 if rand == 2: seq = seq2 if rand == 3: seq = seq3 x = 0 while x < cycle: x = x + 1 for i in seq: GPIO.setup(i, GPIO.OUT) GPIO.output(i, GPIO.HIGH) # main loop try: while True: for i in seq: GPIO.output(i, GPIO.LOW) time.sleep(SleepTimeS); GPIO.output(i, GPIO.HIGH) time.sleep(SleepTimeS); GPIO.output(i, GPIO.LOW) time.sleep(SleepTimeS); GPIO.output(i, GPIO.HIGH) time.sleep(SleepTimeL); except KeyboardInterrupt: print " Quit" GPIO.cleanup() --- þ Synchronet þ The Empty Keg BBS emptykeg.synchro.net:82 Lake Echo NS Canada .