Python, how to export variable?
|
10-16-2023, 08:05 PM
Post: #1
|
|||
|
|||
Python, how to export variable?
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 Some initial learning efforts are shared at https://udel.edu/~mm/hp/ Thanks, Mike |
|||
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. 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)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 |
|||
10-17-2023, 10:01 PM
Post: #3
|
|||
|
|||
RE: Python, how to export variable?
Many thanks, Günter. I don't see export() calls in your programs, or I would happily steal your technique. :-) The eval() I showed executes without error, but seems does not export the variable. Either I'm looking in the wrong place (possible!) or it exists only in scope of that call and is out of scope afterward. To be generally useful, program calculations need to be exportable to stack or variable. All other eval() calls work fine in my code, but no luck yet exporting for use outside python programs. I think there must be a way.
Mike Markowski |
|||
10-19-2023, 07:46 AM
Post: #4
|
|||
|
|||
RE: Python, how to export variable?
(10-17-2023 10:01 PM)ab3ap Wrote: Many thanks, Günter. I don't see export() calls in your programs, or I would happily steal your technique. :-) The eval() I showed executes without error, but seems does not export the variable. Either I'm looking in the wrong place (possible!) or it exists only in scope of that call and is out of scope afterward. To be generally useful, program calculations need to be exportable to stack or variable. All other eval() calls work fine in my code, but no luck yet exporting for use outside python programs. I think there must be a way.There isn't such thing like export. Briefly only as I'm traveling right now. Look at the end of main.py in L- system. Watch out for "AVars". Günter |
|||
10-19-2023, 12:37 PM
(This post was last modified: 11-08-2023 11:59 AM by ab3ap.)
Post: #5
|
|||
|
|||
RE: Python, how to export variable?
Thank you, Günter! I haven't yet read details of creating an app but seems the time has come. Till now, I've simply created .py files and put them in Programs folder.
Mike To keep this thread up to date, I also corrected my previous PPL code: Code: cmd='export X; X:=%e' % n and still no luck with that approach. Now, to read up on apps... |
|||
10-20-2023, 09:13 PM
Post: #6
|
|||
|
|||
RE: Python, how to export variable?
(10-19-2023 12:37 PM)ab3ap Wrote: Thank you, Günter! I haven't yet read details of creating an app but seems the time has come. Till now, I've simply created .py files and put them in Programs folder. Of course no luck. Once again: "That means, the string you hand over to PPL must be something intelligible for PPL." Type that string into the PPL command line and see yourself. BTW, as hpprime.eval() is a function, it always returns something. Günter, still not at home |
|||
11-07-2023, 11:31 PM
Post: #7
|
|||
|
|||
RE: Python, how to export variable?
(10-20-2023 09:13 PM)Guenter Schink Wrote: [...] Of course no luck. [...] Thank you, Günter, and 100% understood. I share that failed effort to new Prime programmers who will inevitably follow my path of trials and errors unless HP (that is, Moravia) updates User's Manual. I'm now successfully sharing results in variables via python App rather than simple programs as I hoped. The result at last is a program performing some useful functions on the job. It has been many years since I've preferred a calculator over a laptop at work. I don't know why, but this makes me happy. :-) Mike |
|||
11-13-2023, 08:39 PM
Post: #8
|
|||
|
|||
RE: Python, how to export variable?
Thank you, @ab3ap, for your write-up!
|
|||
11-13-2023, 09:51 PM
Post: #9
|
|||
|
|||
RE: Python, how to export variable? | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)