Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Value Error handling

def conv(s):
    try:
        s=float(s)
    except ValueError:
        pass    
    return s

print [conv(s) for s in ['1.1','bls','1','nan', 'not a float']] 
# [1.1, 'bls', 1.0, nan, 'not a float']
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Value #Error #handling
ADD COMMENT
Topic
Name
9+4 =