Python Language Tutorial

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Python Language Tutorial

Post by jussij » Wed May 02, 2012 7:35 am

To program in Python using the Zeus IDE do the following.

1) Create a c:\temp\test.py test file using the Python 3.x code shown below:

Code: Select all

print ("Hello world")

result = input("Enter a value: ")

print (result)

print ("Complete.....")
2) Use the Compiler, Compile menu to syntax check the Python code.

3) To run the code use the Macros, Execute 'test.py' menu and in the resulting console window type in 1234 and then hit the enter key.

The following output will be captured inside Zeus:

Code: Select all

---------------------------------------------------------------------------
      Zeus for Windows Programmers Editor - Version 3.97k
      Copyright (c) Xidicone P/L 1993-2012.  All rights reserved.
---------------------------------------------------------------------------

Hello world
Enter a value: 1234
Complete.....
Cheers Jussi

pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener » Thu Jul 26, 2012 6:29 pm

What should the Compiler command line be set to for this? Mine was set to python.exe "$fn", and I got an error that python.exe could not be found.

I'm using your example program from above - I copied it and deleted the blank lines. I tried pythonc.exe too, and got

Code: Select all

---------------------------------------------------------------------------
      Zeus for Windows Programmers Editor - Version 3.97n-beta9
      Copyright (c) Xidicone P/L 1993-2012.  All rights reserved.
---------------------------------------------------------------------------
 **** Unregistered Software. To be used for evaluation purposes only. ****
---------------------------------------------------------------------------


Using document type compiler options....

Hello world
Enter a value: Traceback (most recent call last):
  File "C:\Program Files\Zeus\zScript\testpy.py", line 2, in <module>
    result = raw_input("Enter a value: ")
EOFError: EOF when reading a line
on the compile. Got similar results when running:

---------------------------------------------------------------------------
Zeus for Windows Programmers Editor - Version 3.97n-beta9
Copyright (c) Xidicone P/L 1993-2012. All rights reserved.

Code: Select all

---------------------------------------------------------------------------
 **** Unregistered Software. To be used for evaluation purposes only. ****
---------------------------------------------------------------------------


Scripting Error :> Traceback (most recent call last):
Scripting Error :>   File "c:\Program Files\Zeus\zScript\testpy.py", line 2, in <module>
Scripting Error :>     result = raw_input("Enter a value: ")
Scripting Error :> EOFError: EOF when reading a line

Scripting Error :> Hello world
Scripting Error :> Enter a value:
Macro script generated '20' Debug, Error and/or Warning message(s).
I also tried zpython.cmd with not quite the same results, but very similar.

I know nothing at all about Python, but maybe it's time to change that. What am I doing wrong?

Bill Diener

pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener » Thu Jul 26, 2012 6:54 pm

I've resolved the python.exe not found issue by installing Python 2.7 (duh) and adding it to the path, but still get similar results. Running 3.97 beta9, BTW.

Bill Diener

jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Fri Jul 27, 2012 12:12 am

I've resolved the python.exe not found issue by installing Python 2.7 (duh)

That is one way to do it but the pythonc.exe should also have worked.

The pythonc.exe is a version of the Python 2.7 that comes with Zeus.
but still get similar results. Running 3.97 beta9, BTW.

That is very starange. It is working fine for me at this end :?

Here is my c:\temp\test.py file.

Code: Select all

print "Hello world"

result = raw_input("Enter a value: ")

print result

print "Complete....."
Below I run this file from the command line prompt using the Tools, DOS Shell menu:

Code: Select all

C:\TEMP>pythonc test.py
Hello world
Enter a value: testing
testing
Complete.....

C:\TEMP>
There is also an option to execute Python found at the bottom of the Macros menu and that also worked.

Just open the python file and go to the macros menu.
I know nothing at all about Python, but maybe it's time to change that.

Python : http://www.python.org/doc/
What am I doing wrong?

As you can see from the output the macro did in fact run but something went wrong with the raw_input call.

But I am not sure why that call works at this end :?:

I suggest trying another form of Python input.

Cheers Jussi

pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener » Fri Jul 27, 2012 3:39 pm

When I execute the sample program via the DOS shell or via the run as script menu item, it works just fine. My problem occurs when I try to run it via the F10 (MacroExecuteScript) key. When I enter the name of the script file (containing the sample program), I get the result shown previously.

I still have LUA set as my active scripting language - I don't need to change that, do I?

jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Fri Jul 27, 2012 4:14 pm

My problem occurs when I try to run it via the F10 (MacroExecuteScript) key.

Ok, this now makes sense. The MacroExecuteScript only runs Zeus macros.
When I enter the name of the script file (containing the sample program), I get the result shown previously.

Zeus macros are only a subset of the full macro language.

So for example Zeus macros they don't expect and in fact don't allow input from stdin and this is why it is failing.

If want user input in a Zeus macro you need to use the user_input function.

Code: Select all

function key_macro()
    -- the default command
    local nill = ""

    -- ask for a user for a command line
    input1 = user_input("One Text:", nill, "One User Input Test")

    message_box(0, "One Text: " .. input1)

    -- ask for a user for a command line
    input1, input2 = user_input("One Text:", nill, "Two Text:", nill, "User Input Test")

    message_box(0, "One Text: " .. input1)
    message_box(0, "Two Text: " .. input2)
end

key_macro() -- run the macro
I still have LUA set as my active scripting language - I don't need to change that, do I?
No. A similar Lua macro would fail in a similar way.

Cheers Jussi

dijerydack
Posts: 7
Joined: Sat May 25, 2013 11:02 am

Post by dijerydack » Sun May 26, 2013 9:07 am

If you are using Python 3.x then you will need to use this code:

Code: Select all

print ("Hello world")

result = input("Enter a value: ")

print (result)

print ("Complete.....")
This code will only work for the Python 2.7.x version:

Code: Select all

print "Hello world" 

result = raw_input("Enter a value: ") 

print result 

print "Complete....."

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 1 guest