python newb here

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

python newb here

Post by scottbakertemp » Wed May 25, 2011 7:30 pm

Can anyone tell me why this doesn't work?

f = open("E:\eventghost web server\test.txt")
data = f.read

if data=="622":
eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweroff");
if data=="922":
eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweron");

f.close()

scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

Re: python newb here

Post by scottbakertemp » Wed May 25, 2011 9:11 pm

this is the error message I get:

Traceback (most recent call last):
Python script "2", line 1, in <module>
f = open("E:\eventghost web server\test.txt")
IOError: [Errno 22] invalid mode ('r') or filename: 'E:\\eventghost web server\test.txt'

jonib
Plugin Developer
Posts: 1344
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: python newb here

Post by jonib » Thu May 26, 2011 2:37 am

Try this:

Code: Select all

f = open("E:\\eventghost web server\\test.txt")
jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: python newb here

Post by krambriw » Thu May 26, 2011 6:45 am

Unless you are 100% sure that the data content is exactly the string you write (no white space or hidden chars), I would do like this

Code: Select all

f = open("E:\\eventghost web server\\test.txt")
data = f.read

if data.find("622") != -1:
    eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweroff");

if data.find("922") != -1:
    eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweron");

f.close()

scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

Re: python newb here

Post by scottbakertemp » Thu May 26, 2011 1:19 pm

it gave me an error saying: if data.find("622") != -1:
9:06:59 AM AttributeError: 'builtin_function_or_method' object has no attribute 'find'

I noticed in the latest version of event ghost I can put a query registry action followed by a jump to (if last action was successful) action. I can then add that 2 action combination in the same macro to effectively create an if-then-elseif-statement.

This program is REALLY powerful.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: python newb here

Post by krambriw » Thu May 26, 2011 1:46 pm

Yes, there was one more error in the code:

Code: Select all

data = f.read
should be

Code: Select all

data = f.read()

Post Reply