Sharing Variables between Python and HPppl
|
05-19-2022, 03:43 PM
Post: #8
|
|||
|
|||
RE: Sharing Variables between Python and HPppl
(05-17-2022 01:33 PM)matalog Wrote: How can I share a string variable between a Python program and a HPppl program? No, you can't because PYTHON and HOME don't know anything of each other but ... I do not pretend to really KNOW how these things are working. But from tinkering around I've got some findings that should help. Let me elaborate a bit on this. About hpprime.eval(): it is important to understand that this function only passes on a string to the HOME environment which must be syntactically correct. Therefore you need to ensure the string is understood. A statement like pplname(var) can't do anything because neither pplname nor var have any meaning except perhaps in their environment where they were created. There are methods however to communicate between PYTHON and HOME environments, of which I'll explain the path from PYTHON to HOME consider these two code snippets, first a PPL program Code: EXPORT test(arg1) Let's now create a PYTHON program to see how to interface using hpprime.eval() Code: from hpprime import * Now a close look to the statement: ttt=eval('test('+'"'+arg1+'"'+')') ttt is the variable that receives what is returned from <test(arg1)> eval calls this function with a rather complicated argument. As explained earlier you have to provide a string that's understood by HOME. This is achieved by enclosing it in single quotes. But as you can see there's a lot of almost not discernible quoting. Step by step. Code: eval('test(' is starting the string Sounds complicated, no? The double quotes enclosed in single quotes ensure that the content of arg1 is passed on to the home environment as a string, rather than as a variable name which doesn't exist and would raise an error Conclusion: for using hpprime.eval() you have to create a string that's understood by the home environment. It is important to use single and double quotes as demonstrated in this example because HOME environment has a different interpretation of single quotes. Elsewhere I have already shown that a function: Code: def string(arg): If you got it wrong then ttt will respond with "Error: Syntax Error" Now I'll have a break, but later I'll talk about using AVars which is another way to have PYTHON and HOME exchange contents. Stay tuned HTH Günter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Sharing Variables between Python and HPppl - matalog - 05-17-2022, 01:33 PM
RE: Sharing Variables between Python and HPppl - roadrunner - 05-17-2022, 02:49 PM
RE: Sharing Variables between Python and HPppl - matalog - 05-17-2022, 03:26 PM
RE: Sharing Variables between Python and HPppl - roadrunner - 05-17-2022, 03:45 PM
RE: Sharing Variables between Python and HPppl - roadrunner - 05-17-2022, 03:52 PM
RE: Sharing Variables between Python and HPppl - matalog - 05-17-2022, 11:34 PM
RE: Sharing Variables between Python and HPppl - roadrunner - 05-18-2022, 01:21 AM
RE: Sharing Variables between Python and HPppl - Guenter Schink - 05-19-2022 03:43 PM
RE: Sharing Variables between Python and HPppl - Guenter Schink - 05-19-2022, 07:40 PM
RE: Sharing Variables between Python and HPppl - Ioncubekh - 10-20-2022, 06:57 AM
|
User(s) browsing this thread: 1 Guest(s)