Post Reply 
Discoveries in Python Libraries
10-25-2022, 08:54 PM (This post was last modified: 10-25-2022 08:57 PM by Ioncubekh.)
Post: #1
Discoveries in Python Libraries
Here I will discuss findings about python libraries & stuff

Python <> HPPL variables https://www.hpmuseum.org/forum/thread-18996.html

For matplotl https://www.hpmuseum.org/forum/thread-18992.html

For linalg https://www.hpmuseum.org/forum/thread-16897.html

Creating / saving / accessing files via python program (Python APP is active)

File created below is listed in CAS using AFiles(); but contents not accessed via AFiles("dict.txt")
Code:

from uio import *
# python dictionary with key value pairs
dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
# open file for writing, "w" 
# f type is TextIOWrapper
f = open("dict.txt","w")
# write file
f.write( str(dict) )
# close file
f.close()

Accessing / Reading files is OK from python. Weird thing is that file once read is automatically closed? Once you have issued readlines(), the 2nd time you do it no data is returned. File should remain open till .close()

Code:

f = open("dict.txt","r")
f.readlines() #dumps all file contents on terminal
f.readlines() #no data ???

Regarding CAS in python; xcas seems working. As expected it accepts a valid string because the following operation yield proper results even without importing math or cmath libraries for cos() sin()
Code:

from cas import *
xcas(' int(cos(x) ')
xcas(' diff(sin(x) ')
eval_expr(' solve(3*x+2=9) ')

HP Prime G1
Python via Android Termux...
Find all posts by this user
Quote this message in a reply
10-26-2022, 03:29 AM
Post: #2
RE: Discoveries in Python Libraries
Regarding print()

- fstring print not implemented https://realpython.com/python-f-strings/
- \t doesn't work
Alternative use chr() with space (ANSI code is 32)
Code:
tab=4*chr(32)
print(tab,"how are you",tab)

HP Prime G1
Python via Android Termux...
Find all posts by this user
Quote this message in a reply
11-02-2022, 03:36 AM (This post was last modified: 11-02-2022 03:37 AM by Ioncubekh.)
Post: #3
RE: Discoveries in Python Libraries
Cannot find information regarding timing the execution of python scripts. The help file states utimeq library has this function but don't know how to use it.
Some information here: https://micropython-lego-ri5.readthedocs...q.peektime

Alternative easy stuff:

Code:

EXPORT ppl()
START
PRINT;
PRINT( TEVAL(PYTHON(iname)) ); //both executes & times python script named 'iname'
END;

HP Prime G1
Python via Android Termux...
Find all posts by this user
Quote this message in a reply
Post Reply 




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