Skip to content
Snippets Groups Projects
Commit 1904744e authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[python][test] Add test/example for keyword arguments

parent f7cc9fcb
Branches
No related tags found
1 merge request!86[python] Add support for keyword arguments
Pipeline #31959 failed
......@@ -378,6 +378,15 @@ int main(int argc, char** argv)
// You can also call a lambda function
auto lambda = Python::Callable(Python::evaluate("lambda x,y: (x+y)"));
std::cout << "Result of call to lambda function: " << lambda(foo, bar).str() << std::endl;
// Named arguments can also be passed and mixed with positional ones
using namespace Python::Literals;
using Python::arg;
auto checkIncreasing = Python::Callable(module.get("checkIncreasing"));
std::cout << "Result of checkIncreasing(0,1): " << checkIncreasing(0,1).str() << std::endl;
std::cout << "Result of checkIncreasing(0,1,reverse=False): " << checkIncreasing(0, 1, arg("reverse", false)).str() << std::endl;
std::cout << "Result of checkIncreasing(0,1,reverse=True): " << checkIncreasing(0, 1, "reverse"_a=true).str() << std::endl;
std::cout << "Result of checkIncreasing(1,reverse=True,0): " << checkIncreasing(1, "reverse"_a=true,0).str() << std::endl;
}
......
......@@ -12,6 +12,11 @@ str_list=["string1","string2","string3"]
int_tuple=(1,2,3)
mixed_tuple=((1,2),"three")
def checkIncreasing(a, b, reverse=False):
if (not reverse):
return a<=b
elif reverse:
return b<=a
# some utilities for creating parametrized boundaries
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment