Mark
unread,Sep 21, 2012, 4:41:18 PM9/21/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to shedskin...@googlegroups.com
Dear list members:
I am looking for information on the recommended way to handle mixed return types from function calls. The following code works as expected in Python:
def return_tests1():
return 1, 2.0, 3, 4.0
def return_tests2():
return (1,2), (3,4.0)
def return_tests3():
return (1,2.0), (3,4), (5,6.0)
if __name__ == '__main__':
print return_tests1()
print return_tests2()
print return_tests3()
Output:
(1, 2.0, 3, 4.0)
((1, 2), (3, 4.0))
((1, 2.0), (3, 4), (5, 6.0))
But the types of the returned variables are altered by Shedskin (0.9.2 with Python 2.6 under WinXP). In this case, I get the following:
(1.0, 2.0, 3.0, 4.0)
((1, 2), (3, 4.0))
((1, 2.0), (3, 4.0), (5, 6.0))
Note that the first and third lines differ from the Python results.
I realize that the Shedskin documentation sort of mentions this when it indicates that mixed types in collections are not permitted, but that tuples of length 2 are allowed to have mixed types. In the event that multiple return types are needed from a function call, is the recommended procedure to just pack everything into nested tuples before returning values? Or is there a better solution available?
And as an aside, I would like to express my thanks to all of the Shedskin contributors. I just started working with Shedskin this morning, and am amazed at how simple it has been to get up to speed and get my code compiled (not to mention see HUGE performance gains). It really has been extremely easy. So thanks again,
-Mark