Recently i came across a question & confused with a possible solution, code part is
// code part in result reader
result = map(int, input())
// consumer call
result_consumer(result)
its not about how do they work, the problem is when you are running in python2
it will raise an exception, on result fetching part, so result reader can handle the exception, but incase of python3
a map object
is returned, so only consumer will be able to handle exception.
is there any solution keeping map
function & handle the exception in python2
& python3
python3
>>> d = map(int, input())
1,2,3,a
>>> d
<map object at 0x7f70b11ee518>
>>>
python2
>>> d = map(int, input())
1,2,3,'a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'a'
>>>