Prime Python 101 - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Prime Python 101 (/thread-18069.html) |
Prime Python 101 - hape - 02-23-2022 08:42 AM 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 RE: Prime Python 101 - toml_12953 - 02-23-2022 09:54 AM (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. 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 As you can see, you add Code: #PYTHON name as the first line, then Code: #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. RE: Prime Python 101 - hape - 02-23-2022 12:43 PM That sounds good. If I wanted to call cas for symbolic computation I think the "from cas import *" will do the trick. Sadly there is no help available for the function so maybe someone can help? Say I want to calculate '(x-2)*(x+3)': Using the console i.e. numeric view inside the app I try a naive approach >from cas import * >caseval(CAS.simplify("(x-2)*(x+3)")) unfortunatly does not work. - CAS.simplify is automatically generated when I use Simplify from the toolbox - I noticed that the xtphin-key uses capital X so I type x using the keyboard. Any ideas? What is the difference between xcas-command and caseval-command? thanks a lot RE: Prime Python 101 - Thomas_Sch - 02-23-2022 02:25 PM Using Python please have at look at the threads in this subforum, using search. An example: https://www.hpmuseum.org/forum/thread-18027.html another one with examples by Guenter Schink: https://www.hpmuseum.org/forum/thread-17543-post-152765.html#pid152765 RE: Prime Python 101 - roadrunner - 02-23-2022 05:06 PM (02-23-2022 12:43 PM)hape Wrote: Using the console i.e. numeric view inside the app I try a naive approach Try: >from cas import * >caseval("simplify((x-2)*(x+3))") instead. -road RE: Prime Python 101 - hape - 02-24-2022 05:48 AM I see. Did a lot of reading of the built-in help system and some things started to make more sense. Thanks. Interesstingly there is no help file for the commands under cas tab. Thomas, could not find anything about the caseval/xcas thing. RE: Prime Python 101 - Thomas_Sch - 02-24-2022 08:34 AM (02-24-2022 05:48 AM)hape Wrote: I see.Sorry, but you asked also for help and infos about Prime Python, not only relating the "caseval thing". Please use also the build in help about python libraries. Good success! RE: Prime Python 101 - roadrunner - 02-24-2022 02:28 PM I don't know the what the difference between xcas and caseval is, but caseval("simplify((x-2)*(x+3))") xcas("simplify((x-2)*(x+3))") eval_expr("simplify((x-2)*(x+3))") all return the same thing: 'x^2+x-6' edit: I did find this: https://www.hpmuseum.org/forum/thread-16821-post-147018.html#pid147018 -road RE: Prime Python 101 - parisse - 02-25-2022 08:20 PM caseval, xcas and eval_expr are synonyms (reason behind synonyms is compatibility). |