Python code test from example help

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Python code test from example help

Post by Djek » Mon Nov 17, 2014 9:45 am

hi all,
my first time trying Python, but as usually tying to get knowledge of it.
i wonder if anyone of you noticed problems while trying the example provided by the help,
its about the help comes with PYExec

Code: Select all

*
First ensure Python27.dll and imports are in your Macro Scheduler program folder.
Download and unzip this file:
 
https://www.mjtnet.com/software/python27.zip
 
*/
 
Let>url=http://ip.jsontest.com/
 
/*
python_code:
 
import urllib2
import json
 
# grab data from http://ip.jsontest.com/ - see www.jsontest.com
response = urllib2.urlopen('%url%')
 
# load the json
dict = json.loads(response.read())
 
# get the ip member
myip = dict["ip"]
 
# make a nice string representation of the dict
sdict = json.dumps(dict)
 
# Anything we print to IO is returned in the PYExec output var
print "All Done"
*/
 
//Load the Python code to a variable
LabelToVar>python_code,pcode
 
//Run the code and request the values of the sdict and myip variables ...
PYExec>pcode,output,sdict,myip
 
//Display the IP address
MessageModal>Your pubic IP is: %myip%
I got the python27.zip, and the Python27.dll is already in the MS program directory. And whats left of the zip i also put in the same folder.
But with running this script, i got the error of:
Error exeptions.NameError:name 'pcode' is not defined in the line "PYExec>pcode,output,sdict,myip"
I guess it has to do with importing the libs, but where can i find them?

Thanks for leading me on to the right track,
kind regards,
Djek

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python code test from example help

Post by Marcus Tettmar » Mon Nov 17, 2014 10:46 am

In this example "pcode" is a variable created by LabelToVar which is loading the Python code from the "python_code" label.

If you get this error then pcode does not exist and you have probably just simply failed to step through LabelToVar.

You've probably tried to run the PyExec line on it's own. Make sure you run the whole script FROM THE TOP so that the values are set and the code is loaded.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Python code test from example help

Post by Djek » Mon Nov 17, 2014 12:24 pm

Thanks Marcus,
in the debugger i saw that the defined python value was assigned on the right way to pcode so i didnt get it. :shock:
it looked all right

But i figured it out; :D
on top i have the line: Let>VAREXPLICIT=1
In the debugger the value of pcode is different as the value from %pcode%
If i change the line PYExec>pcode,output,sdict,myip
into PYExec>%pcode%,output,sdict,myip
it works !

Not sure why pcode doesnot react as a normal var, but it is solved.
Of course i tried it with let>VAREXPLICIT=0 and then also no problem.

Thanks.
Djek

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Python code test from example help

Post by Marcus Tettmar » Mon Nov 17, 2014 1:42 pm

If you have VAREXPLICIT=1 then yes you would need that otherwise it will treat pcode as a literal.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Novalak
Newbie
Posts: 9
Joined: Sun Dec 07, 2014 10:23 am

Re: Python code test from example help

Post by Novalak » Wed Dec 10, 2014 5:01 am

ive used the sample script provided and added the dll into the program directory
as soon as a i run the sample, it closes the app

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts