Post Reply 
How can I discover which version of Python I am running?
05-16-2023, 10:30 AM (This post was last modified: 05-16-2023 11:07 AM by StephenG1CMZ.)
Post: #1
How can I discover which version of Python I am running?
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?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
05-16-2023, 12:09 PM
Post: #2
RE: How can I discover which version of Python I am running?
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)
Find all posts by this user
Quote this message in a reply
05-16-2023, 07:19 PM
Post: #3
RE: How can I discover which version of Python I am running?
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
Find all posts by this user
Quote this message in a reply
05-17-2023, 07:04 AM (This post was last modified: 05-17-2023 08:14 AM by StephenG1CMZ.)
Post: #4
RE: How can I discover which version of Python I am running?
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
05-21-2023, 08:48 PM (This post was last modified: 05-21-2023 08:49 PM by StephenG1CMZ.)
Post: #5
RE: How can I discover which version of Python I am running?
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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