Post Reply 
Python, how to export variable?
10-17-2023, 07:04 PM
Post: #2
RE: Python, how to export variable?
(10-16-2023 08:05 PM)ab3ap Wrote:  I bought a Prime a month or so ago and I'm enjoying learning how to program it with python. The lack of official python docs (at least that I can find) make it more challenging, but I'm making progress.

One thing I haven't succeeded at yet and seems should be easy, is how to export a variable from python. Trying to export 'n' into variable 'x' like this doesn't seem to work:

Code:
cmd = 'x=%e; export x' % n
hpprime.eval(cmd)

Some initial learning efforts are shared at https://udel.edu/~mm/hp/

Thanks,
Mike

Nice web site you've set up. Now to your problem. As you have figured hpprime.eval() is the key to interface between PPL and Python.
Quote:hpprime.eval(string)

Evaluates string as a PPL command line.
Since strings can be dynamically created, this allows you to communicate from Python to PPL and send data from the Python world to the PPL world, and/or to use facilities available in the calculator but not in Python.
The PPL result will be returned as a Python object if possible (numbers, complexes, strings), else it will be converted into a Python string"
That means, the string you hand over to PPL must be something intelligible for PPL.

I've created two apps that might be of interest and where some features of hpprime.eval() are used.
Mandelbrot Explorer and
Lindenmayer Fractals
Look for hpprime.eval() there, perhaps you can take something from there.

Günter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python, how to export variable? - ab3ap - 10-16-2023, 08:05 PM
RE: Python, how to export variable? - Guenter Schink - 10-17-2023 07:04 PM



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