Passing values from PPL to Python and vice versa - an alternative to AVars
|
12-08-2023, 06:45 PM
(This post was last modified: 12-08-2023 06:49 PM by komame.)
Post: #7
|
|||
|
|||
RE: Passing values from PPL to Python and vice versa - an alternative to AVars
Hi Günter,
I'm glad that you managed to make my examples work I noticed another additional benefit of using the approach I proposed, which concerns converting values to numbers. When you pass a numeric value as a parameter using the standard method in a PYTHON command, e.g., PYTHON(pycode, 12345.456), the argv[0] on the Python side is of the string type, not float. Furthermore, the content of argv[0] depends on the HSeparator settings and varies accordingly. For values higher than 999, you must use HSeparator=3 for calculations involving argv[0]. Without this, the values can't be converted to a number, as float(argv[0]) will raise a syntax error due to the digit grouping separator, leading to a failed conversion, even in the absence of the garbage. However, with my proposed method, a value of the float type is directly assigned to the Python variable, allowing for more HSeparator settings (0, 1, 2, 3, 9, 10), with each resulting in a correct number. The following program demonstrates an attempt to convert the parameter passed in argv[0] to a number vs reading values directly from a PPL variable: Code: #pragma mode( separator(.,;) integer(h64) ) Although some garbage appeared in certain iterations during the call using standard method, even without the garbage, the conversion would have failed due to digit grouping separators. This indicates that reading values directly from a variable is much more flexible than passing them using the standard method. regards, Piotr |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)