Page 1 of 1

python newb here

Posted: Wed May 25, 2011 7:30 pm
by scottbakertemp
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()

Re: python newb here

Posted: Wed May 25, 2011 9:11 pm
by scottbakertemp
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'

Re: python newb here

Posted: Thu May 26, 2011 2:37 am
by jonib
Try this:

Code: Select all

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

Re: python newb here

Posted: Thu May 26, 2011 6:45 am
by krambriw
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()

Re: python newb here

Posted: Thu May 26, 2011 1:19 pm
by scottbakertemp
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.

Re: python newb here

Posted: Thu May 26, 2011 1:46 pm
by krambriw
Yes, there was one more error in the code:

Code: Select all

data = f.read
should be

Code: Select all

data = f.read()