Post Reply 
Python: ZSYS module (mimics SYS)
05-21-2023, 08:24 PM (This post was last modified: 05-21-2023 08:30 PM by StephenG1CMZ.)
Post: #1
Python: ZSYS module (mimics SYS)
ZSYS aims to mimic some of the functionality of the sys module, which is provided with most python's, but is absent from the micropython on most calculators.

The aim of the initial implementation serves two purposes:
To attempt to identify which calculator is running, which may be useful in tweaking portable code.
And to emulate some functions that portable code might call in sys, where it is unavailable.

Note: Those versions of the HP Prime that support Python will have sys built-in. Just use sys, unless you wish to make your code portable.

With thanks to the contributions from this thread:
https://www.hpmuseum.org/forum/thread-19962.html

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:27 PM (This post was last modified: 10-09-2024 08:16 AM by StephenG1CMZ.)
Post: #2
RE: Python: ZSYS module (mimics SYS)
Version 0.1 of ZSYS identifies calculator makers.
(Specific calculators cannot generally be identified).




Code:


"""ZSYS mimics part of sys where needed.

It allows portable code to identify calculator platforms despite most calculators not having sys.
"""

crme="""
© 2023 StephenG1CMZ
"""
crid="ZSYS v0.1"+crme
impname="micropython" #unless sys exist
impversioninfo=None #version unknown
platform="" #sys.platform
#Note that detecting files from these
#does not guarantee which is running
isCasio=False
isHP=False
isNumworks=False
isPrime=False
isTI=False
isCalculator=False
calculators=""
isSys=False

try:
  import sys
  platform = sys.platform
  #sys.implementation
  #impname = sys.implementation.name
  #impmachine = sys.implementation.machine
  impversioninfo=sys.implementation.version_info
  isSys=True
  try:
    if sys.platform == "HP Prime":
      isPrime = True
    else:
      isPrime=False
  except:
    isPrime=False

except:  #only examine files if no sys
  #reason: exclude false positives from imposters
  try: #Casio
    import casioplot
    isCasio=True
    platform="Casio"
  except:
    isCasio=False 

  try: #Numworks
    import ion
    isNumworks=True
    platform="Numworks"
  except:
    isNumworks=False
  if isNumworks:
    try:
      import os
      fork="Omega" #alternative
    except:
      fork="Epsilon" #Main

  try: #TI
    import ti_system
    isTI=True
    platform="TI"
    hhdt=get_platform()
  except:
    IsTI=False

if isPrime:
  #identifiable calculator
  isHP=True

if isCasio or isHP or isNumworks or isTI:
  isCalculator=True
  calculators=" calculator"

def exit(exc=0): #mimic sys.exit
  raise SystemExit(exc)

def main():
  #micropython, cpython etc.
  print(impname,impversioninfo)
 #from sys, or Calculator maker
  print(platform,calculators)

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

    if isTI:
      #handheld/desktop
      print(get_platform()) #hh/dt=handheld/desktop

showme=True #customise
showmore=True #customise

if showme or __name__ == "__main__":
  print(crid)
  main()

Note: Since Python has yet to reach HP Prime Android, it is currently tested only on Numworks.
Update 2024: It fails to run on HP Prime!

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, 10:02 PM
Post: #3
RE: Python: ZSYS module (mimics SYS)
(05-21-2023 08:27 PM)StephenG1CMZ Wrote:  Note: Since Python has yet to reach HP Prime Android, it is currently tested only on Numworks.

Why not simply test it on a Prime device??

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
05-21-2023, 11:26 PM (This post was last modified: 05-22-2023 08:48 AM by StephenG1CMZ.)
Post: #4
RE: Python: ZSYS module (mimics SYS)
Well, since you asked...
Local shops don't sell it (they do sell Casio, but without Python).
And I haven't bought anything mail-order for myself since attempting to buy a radio, which the guy at the post office would only hand over to Mr. G1CMZ - I didn't have a matching birth certificate.

Also, I have always got a phone with me I know how to cut-and-paste code from an App.
But the real HP Prime doesn't have standard WiFi, so I imagine I would have to mess around with and carry cables, OTG dongles and the like (not to mention the calculator)?

The Numworks App just works*, wherever I am.

*The HP Prime version may require a phone signal.
https://www.hpmuseum.org/forum/thread-15...ime+broken

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
10-09-2024, 08:12 AM (This post was last modified: 10-09-2024 10:08 AM by StephenG1CMZ.)
Post: #5
RE: Python: ZSYS module (mimics SYS)
CAUTION!
Attempting to run ZSYS on the HP Prime Python App on Android crashes back to Android. Has anyone managed to run ZSYS on HP Prime?

I suspect an issue with the HP Prime Python App, as on Numworks it runs OK.

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
10-09-2024, 09:22 PM
Post: #6
RE: Python: ZSYS module (mimics SYS)
It runs on the virtual Prime on Win 11

on Android ... no more ranting today Sad

Günter
Find all posts by this user
Quote this message in a reply
10-10-2024, 04:40 PM
Post: #7
RE: Python: ZSYS module (mimics SYS)
Thanks for that, nice to know it works on G2 and virtual Prime, just not the buggy Android app.

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
10-17-2024, 08:09 PM (This post was last modified: 10-18-2024 09:31 PM by Guenter Schink.)
Post: #8
RE: Python: ZSYS module (mimics SYS)
(10-10-2024 04:40 PM)StephenG1CMZ Wrote:  Thanks for that, nice to know it works on G2 and virtual Prime, just not the buggy Android app.

I now had a closer look to this little program. Although it runs without obvious errors, it seems to be not correct. Because it didn't show correct information i went to check it a little bit.

MicroPython at least according to the link doesn't have "sys.implementation.version_info". Either "sys.version", "sys.version_info" or "sys.implementation". These information are available on the prime also. "sys.implementation" provides the release version of MicroPython whereas the "versions" show wich CPython it's based on.

sys.implementation[1] returns a tuple of the version.(major,minor, micro). So does sys.implementation.version

On my older Numworks calculator, there is no sys module, and it seems they aren't there on newer models either.

Günter

Edit: added sys.implementation.version
Find all posts by this user
Quote this message in a reply
10-22-2024, 03:51 PM (This post was last modified: 10-22-2024 03:53 PM by StephenG1CMZ.)
Post: #9
RE: Python: ZSYS module (mimics SYS)
Thanks for that feedback Guenter.
Apparently that sys.implementation.version_info that I tried to use only exists in the Python sys module, not the micro python sys module.

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)