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
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
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)This is the errorError: Traceback (most recent call last):
Python script "9", line 9, in <module>
exit()
NameError: name 'exit' is not definedThanks 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.
