When I do floating point division in Python, if I divide by zero, I get an exception:
>>> 1.0/0.0 Traceback (most recent call last): File \"
If i understand your problem properly then this should be the solution:
try: 1.0/0.0 except: return 'inf'
you can modified it according to various python exception handling method available