Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Wed Nov 04, 2015 12:41 pm
The following code works fine.
Code: Select all
/*
python_code:
x = "Hello"
print("Hello The World")
*/
//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,x
MDL>output
Question:
How to display "Hello The World" inside the Python code above?
Thank you for your help in advance.
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Wed Nov 04, 2015 1:47 pm
Marcus Tettmar wrote:What do you mean?
If Python displays a message by means of print ("....."), it has to relay the message to output in: PYExec>pcode,output,x.
Is it possible for a Python code displays messages directly onto screen instead of thru MS?
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Wed Nov 04, 2015 1:59 pm
You mean you want it to display some kind of dialog, like a message box.
So I Googled that for you. There are various dialog libraries but ideally we want one that comes as standard with Python so you don't have to install custom library files.
Googling "Python Message Box" we get this as top result:
http://stackoverflow.com/questions/2963 ... -in-python
Second post there says ctypes is standard, so lets use that:
Code: Select all
/*
python_code:
import ctypes # An included library with Python install.
msg = "Hello World"
ctypes.windll.user32.MessageBoxA(0, msg, "Message", 1)
*/
//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,msg
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Wed Nov 04, 2015 2:13 pm
Marcus Tettmar wrote:You mean you want it to display some kind of dialog, like a message box.
Yes, that's exactly what I asked for.
Marcus Tettmar wrote:So I Googled that for you. There are various dialog libraries but ideally we want one that comes as standard with Python so you don't have to install custom library files.
Thanks for your generous effort in finding and constructing a working solution. Now I just follow your direction to learn more about Python language.
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Wed Nov 04, 2015 2:16 pm
Can MS support Python 3.5 64-bit?
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Wed Nov 04, 2015 2:31 pm
What? No. Macro Scheduler is 32 bit and the latest it supports is 2.7.
However I believe this is irrelevant to the thread. You have posted a screen shot of running the Python Print function inside the Python shell. You don't need Python 3.5 to do that. Python 2.7 can do the same. But it's irrelevant. You're not running code in the shell, you're wanting to run code inside Macro Scheduler. Print can't therefore do anything noticeable in this context. PyExec instead returns the output buffer.
The Print function outputs to the console. Rather like Echo in a console VBScript, or SOWrite/SOWriteLn in a compiled console application Macro Scheduler macro. But there's no console when you're running inside Macro Scheduler.
Clearly there's no console when you're running inside Macro Scheduler so Print would have nowhere to go ... you wouldn't see anything. Just the same as running SOWrite in debug mode or in a non console macro would appear to do nothing - because there is no console.
But what PyExec does is return anything that WOULD have been output to the console instead. That's why your Output variable in your example shows "Hello the world".
If we wanted something displayed DURING the execution we could use a message box which is what I thought you were asking for. And that is what I showed you.
So, nothing to do with which version of Python you are using. You asked for a dialog/message box. I showed you code for that.
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Wed Nov 04, 2015 3:01 pm
Marcus Tettmar wrote:What? No. Macro Scheduler is 32 bit and the latest it supports is 2.7.
Thank you for your effort in elucidating the conceptual implementation of Python under MS.
Thank you for helping me understanding the conceptual connection among echo, SOWrite/SOWriteLn, and console.
Thank you for speeding up my Python learning.