HP Forums
How can I discover which version of Python I am running? - 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: How can I discover which version of Python I am running? (/thread-19962.html)



How can I discover which version of Python I am running? - StephenG1CMZ - 05-16-2023 10:30 AM

So far I have this (tested only on Numworks):
Code:

"""XMH Explore My Host.
This version identifies which calculator you are on.
"""

crme="""
© 2023 StephenG1CMZ
"""
crid="XMH\nExplore My Host"+crme

try:
  import casioplot
  isCasio=True
except:
  isCasio=False

try:
  import ion
  isNumworks=True
except:
  isNumworks=False

if isNumworks:
  try:
    import os
    fork="Omega" #alternative
  except:
    fork="Epsilon" #Main

try:
  import ti_system
  isTI=True
except:
  IsTI=False


print(crid)
if isCasio:
  print("Casio")

if isNumworks:
  print("Numworks", fork)
  if fork=="Omega":
    print(os.name)

if isTI:
  print("TI")

if isCasio or isNumworks or isTI:
  isCalculator=True
else:
  isCalculator=False
  print("Unrecognised Host")

With the news that Python may be coming to the HP Android, I wonder how it might best be recognised?


RE: How can I discover which version of Python I am running? - drbarnack - 05-16-2023 12:09 PM

You could try something that uses sys.platform like

Code:

try:
    import sys

    try:
        if sys.platform == "HP Prime":
            IsPrime = True
        else:
            IsPrime = False
    except AttributeError:
        IsPrime = False

except ImportError:
    IsPrime = False

print("IsPrime:", IsPrime)



RE: How can I discover which version of Python I am running? - Guenter Schink - 05-16-2023 07:19 PM

You could also use, similar to Casio and Ti:

Code:
try:
  import hpprime
  IsPrime = True
except:
  IsPrime = False

print("IsPrime = ", IsPrime)
No need to resort to "sys" library

Günter


RE: How can I discover which version of Python I am running? - StephenG1CMZ - 05-17-2023 07:04 AM

Ah, so there are two alternatives.
The try import hpprime matches how the other calculators are detected.
But the prime version also has sys.platform.
That has the advantage that sys.platform will also show if the code is running on non-calculator hosts.


RE: How can I discover which version of Python I am running? - StephenG1CMZ - 05-21-2023 08:48 PM

I have placed a version here, using the built-in sys where it is available:

https://www.hpmuseum.org/forum/thread-19989.html

Tested only on Numworks as Python has yet to reach HP Prime Android.