Python Script Error
#1
Hello all,

I have recently come across an error with my Python script.
I am very new to python so it's probably just a really simple problem.

I have written a little script that will check if my external hard drive is mounted.
It does this by checking if a file is available on the drive.

But XBMC always returns "else: < invalid syntax on line 19".

I have tried different solutions that I have found on Google but none seem to work.

Here is the script:
PHP Code:
import os
import os
.path
import xbmc
import time

#This is the drive that the script will check for
PATH xbmc.getinfolabel('Skin.String(DriveMount)')

#This will put everything in to a loop
while True:

#This will check the drive and see if the Drive file is available
#If the file exists it will notify the user saying the drive is mounted
  
if os.path.isfile(PATH 'Drive.xbe') and os.access(PATH 'Drive.xbe'os.R_OK):
    print 
"File exists and is readable"
xbmc.executebuiltin('Notification(External Storage, Your external drive is mounted and ready to use,5000,)')
return 
False
#If the drive isn't mounted or file isn't available then it will search again
else:
xbmc.executebuiltin('Dialog.Close(1929)')
   print 
"Either file is missing or is not readable"
#Sleep for a few seconds to lower CPU usage
time.sleep(5)

while 
False:
#This will make sure that the drive is mounted 
#When unmounted it will then watch to see if it is mounted again
if os.path.isfile(PATH 'Drive.xbe') and os.access(PATH 'Drive.xbe'os.R_OK):
    print 
"File exists and is readable"
#If the drive isn't mounted then it will start over
else:
    print 
"Either file is missing or is not readable"
return True
#Sleep for a few seconds to lower CPU usage
time.sleep(5

Thank you for any help in advance Smile
Reply
#2
you have improper python formatting/indenting:

it needs to be
PHP Code:
#This will check the drive and see if the Drive file is available
#If the file exists it will notify the user saying the drive is mounted
  
if os.path.isfile(PATH 'Drive.xbe') and os.access(PATH 'Drive.xbe'os.R_OK):
    print 
"File exists and is readable"
    
xbmc.executebuiltin('Notification(External Storage, Your external drive is mounted and ready to use,5000,)')
    return 
False
    
#If the drive isn't mounted or file isn't available then it will search again
  
else:
    
xbmc.executebuiltin('Dialog.Close(1929)')
    print 
"Either file is missing or is not readable"
#Sleep for a few seconds to lower CPU usage
time.sleep(5
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
@Martijn :

Thanks for the quick reply, I am unable to test this out on XBMC at the moment as I am not at home, but I quickly tested it out on www.compileonline.com and this returns "else: < invalid syntax on line 19" the same as XBMC does.

I will give it another go when I get back home though.
Reply
#4
ah made a slight error in the indent. fixed the post.
problem is definitely your code syntax indenting
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
Thanks Martjin!
I have just tested out the changes and it all seems to be working perfectly now Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Python Script Error0