How can we return more than one value using Python-Ladon functions?
Asked
Active
Viewed 324 times
0
-
what are Ladon functions? Do you mean [`lambda` functions](http://docs.python.org/reference/expressions.html#lambda)? – glglgl Oct 09 '12 at 08:46
-
may be he's taking about http://packages.python.org/ladon/ladontype.html – Ashwini Chaudhary Oct 09 '12 at 08:49
1 Answers
1
You can return more values by wrapping them into a list inside a class that you use as the returntype in the decorator ladonize
.
Based on an example in the documentation for ladon:
from ladon.ladonizer import ladonize
from ladon.types.ladontype import LadonType
class Response(LadonType):
values = [int]
class MyService(object):
@ladonize(int, int, rtype=Response)
def foo(self, a, b):
result = Response()
result.values = [a+b, a*b]
return result

halex
- 16,253
- 5
- 58
- 67
-
thanks, it works, can we possible to return more than one dictionaries, lists etc using this method? – user1059150 Oct 09 '12 at 11:57
-
@user1059150 You can return an instance of a class, and inside the class there may be different datatypes. The class can have variables that are different classes itself but at the end every datatype must have a path that leads to one of the 5 primitive types. Study [this example](http://packages.python.org/ladon/index.html#example-2) from the documentation. The caller can retrieve the data from the returned instance . See http://packages.python.org/ladon/ladontype.html#ladontype-for-complex-service-types for more information. – halex Oct 09 '12 at 16:26