Post Reply 
Prime Python 101
02-23-2022, 09:54 AM
Post: #2
RE: Prime Python 101
(02-23-2022 08:42 AM)hape Wrote:  After connecting my prime to the connKit the firmware update was done, so I have python on the prime again. The wait(-1) thing was really annoying for me the last time I used the calculator because some functions I wrote in the past did not run anymore which is why I did not play with python till now. Decision to start over from scratch with the prime was made during the weekend and so...yes python.


Can someone give advice on how I am supposed to write functions or programs using python? Of course I have found the python app.
Inside the app I can switch to symb-view and see a main.py window which is where I suppoose I could write a program. If I switch from symb to numView, prime crashes and reboots. Reliably. :-(


Question: do I code under PythonApp-Symb view or can I code in the traditional Program Catalog?

Question: Where do PythonPrograms show up? Toolbox/user or somewhere else? Can/Should I kind of Export python functions?

Question: Python seems to be almost a hidden feature. I am surprised that I do not find information comparable to HPPL. Is there any structured tutorial out there?


I have a Prime G1, Prime Android App (not in use at all, makes no sense on a touch device I think) and have ordered a Prime G2. In case python might behave differently on different platforms.

Thank you and have a nice day

What I do is to edit my Python program right in the regular program editor by putting the Python program in an HPPL wrapper like this:
Code:
#PYTHON name
from math import *
from hpprime import *
t = eval("ticks")
loops = 30000
for i in range(loops):
    r0 = 10
    while True:
        x = r0
        x += 1
        x -= 4.567E-4
        x += 70
        x -= 69
        x *= 7
        x /= 11
        r0 -= 1
        if r0 <= 0:
            break
    x = log(x)
    x = sin(x)
    x = sqrt(x)
    x = sqrt(x)
print(x)
t = (eval("ticks")-t)/1000
print("Loops:", loops)
print("Time: {0:.3f} seconds".format(t))    
print("Index: {0:.2f}".format(34/t*loops))
#end
EXPORT calcperf()
BEGIN
  PYTHON(name);
END;

As you can see, you add

Code:
#PYTHON name

as the first line, then

Code:
#end
EXPORT calcperf()
BEGIN
  PYTHON(name);
END;

after the Python program. Change "calcperf" to whatever name you want to call your own routine.
In this example, calcperf will show up in the list of HPPL programs and can be run from there.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Prime Python 101 - hape - 02-23-2022, 08:42 AM
RE: Prime Python 101 - toml_12953 - 02-23-2022 09:54 AM
RE: Prime Python 101 - hape - 02-23-2022, 12:43 PM
RE: Prime Python 101 - roadrunner - 02-23-2022, 05:06 PM
RE: Prime Python 101 - Thomas_Sch - 02-23-2022, 02:25 PM
RE: Prime Python 101 - hape - 02-24-2022, 05:48 AM
RE: Prime Python 101 - Thomas_Sch - 02-24-2022, 08:34 AM
RE: Prime Python 101 - roadrunner - 02-24-2022, 02:28 PM
RE: Prime Python 101 - parisse - 02-25-2022, 08:20 PM



User(s) browsing this thread: 1 Guest(s)