ParseTupleAndKeywords in R20
-
We are adding new Python functions to Cinema and our solution works fine in R19 and previous versions but we are having problems parsing the parameters in R20
static _PyObject *MyprojectPyAPI_MakeThing(_PyObject *self, _PyObject *args, _PyObject *keywords) { PythonLibrary pylib; String str; const Char *kwlist[] = { "str", nullptr }; if (!pylib.ParseTupleAndKeywords(args, keywords, "$", kwlist, &str)) return nullptr; #if API_VERSION < 20000 if (str.Content()) #else if (str.IsEmpty()!=false) #endif { Utils::addLog("Parameter is: " + str); } else { Utils::addLog("Cannot parse the parameter correctly."); } return pylib.ReturnPyNone(); }
As you can imagine the problem is that it always throws "Cannot parse the parameter correctly."
Any idea on what is wrong for R20? something related to PythonLibrary changed?
Thank you in advance!
-
Hi Victor,
Only minor changes/fixes have been made to the PythonLibrary and its behavior hasn't changed in R20. So parsing a String with $ should still work fine.
How do you call the function and pass the string? What's the exact error message?
-
I didn't change nothing from the version that works ok in R19
moduleFunctions[0].Init("MakeThing", (PyFn)MyprojectPyAPI_MakeThing, PYFN_FLAGS::KEYWORDS, "MakeThing(str path)");
-
Hi Victor,
There's a logic error in the code you posted from the first post. The condition for R20
if (str.IsEmpty()!=false)
returns false if the string has content.
It makes more sense to callIsPopulated()
for the R20 code instead ofIsEmpty()
. -
@y_puech said in ParseTupleAndKeywords in R20:
Hi Victor,
There's a logic error in the code you posted from the first post. The condition for R20
if (str.IsEmpty()!=false)
returns false if the string has content.
It makes more sense to callIsPopulated()
for the R20 code instead ofIsEmpty()
.You are right, thank you!!!