Search
 
SCRIPT & CODE EXAMPLE
 

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']
Comment

PREVIOUS NEXT
Code Example
Python :: for c in range python 
Python :: replace substrings to float 
Python :: convert numpy array to byteslist 
Python :: i want to check my python code online 
Python :: else if in pyton 
Python :: how make aloop in python 
Python :: reset all weights tensorflow 
Python :: input character in python like getchar in c 
Python :: how to take input a matrix using map in python 
Python :: decode base64 password python 
Python :: /bin/sh: 1: python: not found code runner 
Python :: 1047 uri solution 
Python :: The simplest way to start using doctest in python 
Python :: Print Multiple Variables 
Python :: Reverse Bits Algo 
Python :: Django is MVT Not MVC 
Python :: py decorateur 
Python :: python check vpn ip address 
Python :: Using pushbullet to export whatsapp chat 
Python :: webcolors python 
Python :: how to install apps in django 
Python :: pandas get most occurring value for each id 
Python :: using django annotations to get the last record 
Python :: NAME.append (Line.split(",")[1].rstrip()) IndexError: list index out of range 
Python :: dictionart 
Python :: Django-rest-framework-simplejwt.readthedocs.io 
Python :: python Access both key and value using items() 
Python :: django queryset or operator 
Python :: how to change pi hostname in python file 
Python :: python + credit-german.csv + class 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =