Passing values from PPL to Python and vice versa - an alternative to AVars
|
12-06-2023, 07:56 AM
Post: #5
|
|||
|
|||
RE: Passing values from PPL to Python and vice versa - an alternative to AVars
(12-05-2023 10:35 PM)Guenter Schink Wrote: Sorry Piotr, I believe it doesn't. To verify this, you first have to delete the user variable "pyresult" because it certainly contains what's left over from the various checks you already have done. Hi Günter I still maintain that it works Just test it on the emulator or on a real Prime. To convince you, I inform you that I restored the factory settings on my Prime, so I have no variables other than the built-in ones. Then I loaded this program, and everything still works as before. The whole phenomenon of this solution lies in the fact that Prime, from the PPL level, can read local variables from other PPL programs, and they don't have to be of the EXPORT type. In the case of Python on Prime, I use this feature of the PPL language and simply read and write to/from local variables. Calling local functions works the same way. It's not well-documented, but it has been in PPL since the beginning. (12-05-2023 10:35 PM)Guenter Schink Wrote: Alternatively change "numbers= range(10)" to "numbers = range(7)" and check the result. I can change the range value, and each time the list displays correctly. (12-05-2023 10:35 PM)Guenter Schink Wrote: In addition I think it's always wise to check the result of an hpprime.eval() statement. I.e change the line: The "print(check)" produces the same list (correctly). (12-05-2023 10:35 PM)Guenter Schink Wrote: A minor thing: It's superfluous to end a Python line with ";" Yes, I'm aware of that. Just switching between programming languages like PPL, Python, C#, C++ or ABAP, I might inadvertently insert an extra character that is required in another language (but it's not a syntax error). (12-05-2023 10:35 PM)Guenter Schink Wrote: The fact that you always see the seemingly correct result is owed to the the variable "pyresult" never being changed during your various tests. The "PYPPL.pyresult" is a valid expression in PPL as long as there is a PYPPL program that contains a local variable (in the header, not inside a function) named "pyresult". In reality, there is no difference between LOCAL and EXPORT variables other than the fact that EXPORT appears in "User variables" and can be referenced directly by name, while LOCAL is not visible in "User variables" and requires a prefix with the program's name to reference. Here's a simple example: - create new program "PRG" - enter: Code: LOCAL MYVAR:="ABC"; - enter: PRG.MYVAR and you see the "ABC" as a result. Best wishes, Piotr Piotr Kowalewski |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)