Hi Guys. I'm just starting to learn Python
I have a short script that is supposed to play a random wav file in a folder but only between 9 and 5
It returns an error and I'm not sure what I have done wrong
This is the error
I have a short script that is supposed to play a random wav file in a folder but only between 9 and 5
It returns an error and I'm not sure what I have done wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from os.path import isfile, join from os import listdir import random import datetime hr = datetime.datetime.now().hour if hr < 9 or hr > 17 : exit() #path you want to get wav files from path = "C:\Sounds\Clock Sounds for EG\Doorbell" onlyfiles = [ f for f in listdir(path) if isfile(join(path,f)) ] onlywavfiles = [] for f in onlyfiles: if f[ - 3 :] = = "wav" : onlywavfiles.append(f) #generate random number based on number of available files randomnum = random.randint( 0 , len (onlywavfiles) - 1 ) eg.plugins.System.PlaySound(path + "/" + onlywavfiles[randomnum], 1 , False ) |
Error: Traceback (most recent call last):
Python script "9", line 9, in <module>
exit()
NameError: name 'exit' is not defined
Thanks Patricia
nilamo write Feb-08-2021, 09:53 PM:
Please use code tags in the future, to preserve whitespace. I've added them for you this time.
Please use code tags in the future, to preserve whitespace. I've added them for you this time.