HP Forums

Full Version: Python version on the HP Prime
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi to all,
i am a programming novice interested in astronavigation. I want to write a sight reduction program including the calculation of the most imiportant ephemeris data for sun and the brighter stars. I found some great py code that I can use. but, alas, the code does not run on the HP Python. I managed to import it to the Prime via connectivity kit (thanks to the help I got here in the forum). Anyone familiar with the python version on the HP please help me with data on the documentation of this version. the link to the code on the sun ephemeris is: https://www.celnav.de/page3.htm, sunmoon almanac by hennig Umland.
thank you very much in advance, greetings kunze
It's Micropython.
See e.g. https://www.hpmuseum.org/forum/thread-16862.html
From the build in help (start the python app, then press Help), page 2:
"HPPrime uses micropython 3.4. (You should be able to find all the documentation at https://micropython.org/). "
Micropython uses only a subset of python.

sunmoon (Sun and Moon Almanac 0.92 by H. Umland) maybe uses functions net contained in micropython, and/or you need to include other libraries.

Edit: In the full Help go to "Tree", "Search", "Python all_modules",
there all all available modules listed. (builtins, micropython, uarray, uio, ...)
HI Thomas, thank you very much" Herzlichen Dank! lg Kuenze
The prime has a few issues with the sun_moon.py code:

a. fsum and isclose do not exit in the math module.
b. exit is in the sys module

To fix this i put the following code at the top of the file:

Code:
from builtins import sum as fsum
from builtins import abs
from sys import exit

def isclose(a,b,abs_tol):
    return abs(a-b)<abs_tol

Then I went thru the code and replace math.fsum with fsum and math.isclose with isclose.

With these changes it runs on the prime and seems to give results similar to the original file when run in spider. You may want to change the print statements to fit better on the prime's screen.

The file is attached below with the extension changed to .txt.

-road
[attachment=10367]
(02-14-2022 07:07 PM)roadrunner Wrote: [ -> ]The file is attached below with the extension changed to .txt.

-road

Also in reply to the email of Martin. I had a cursory look at the program. Line 7 has a typo
def isclose(a,b,abs_to:):
needs to be changed to:
def isclose(a,b,abs_tol):

that is: replace the colon prior to the closing parentheses with an "l"

Otherwise it seems to run almost error free. A bug in the printing command shows up however. When you print characters with ASCII code higher than 128 the printout is garbled. There is a solution however and that is graphical text output.
[edit] it is the "°" character that disturbs the print out[/edit]

@kuenze: Martin, I can't give you more advice than you have received already here. But I think that I can do something on input and output. But that will take its time.

Günter
Dear Günther,

thank you very much for your advice! deleting the "°" string helps and I will substitute with with "deg". in case that doesn't solve all issues I´ll come back to your kind offer. lg Kuenze
Looks like an interesting program. As it is tailored for a wider output than the Prime provides, some beautifying actions are necessary. In my very first approach:
[attachment=10383]
  • replaced all the "----" and "====" strings by "-"*20 and "="*20 thus providing an easy method to adjust the width of these lines later at will
  • replaced "°" by "dg" as this doesn't exist anywhere in the code, that makes it easier to replace them later again ("°") causes garbled output of the "print" command
  • Some output lines had arbitrary line brakes. Fixed a couple of them
  • in order to have a reasonable display, the system font should be "Small Font"
  • spacing with blanks doesn't really work on the Prime, hold your breath for a nicer solution Smile
Next will be an input form, that retains the values you have entered.

BTW this code perfectly runs on my Windows PC as well as on my Android devices (Pydroid 3)
BTW 2: I don't have any knowledge of the Astro subject, simply tampering with the code Smile

Günter
Günther, thanks a lot! greetings Kunze
Reference URL's