Python Forum
Short code for EventGhost not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Short code for EventGhost not working
#1
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
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 error
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.
Reply


Messages In This Thread
Short code for EventGhost not working - by Patricia - Feb-08-2021, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 962 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 892 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,017 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,083 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,931 Mar-21-2022, 10:12 AM
Last Post: End3r
  I don't undestand why my code isn't working. RuyCab 2 1,992 Jun-17-2021, 03:06 PM
Last Post: RuyCab
  code is not working , can anybody help? RandomPerson69 4 2,913 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Code no longer working yk303 14 10,180 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  How can I make a short-key in Spyder (Python IDE)? moose 3 2,688 Nov-02-2020, 12:13 PM
Last Post: jefsummers
  autocomplete working code sample not working... aviper4u 0 1,642 Oct-24-2020, 03:04 AM
Last Post: aviper4u

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020