change a value to NULL?

Laszlo Zsolt Nagy gandalf at
Wed Oct 5 18:17:49 CEST 2005

Bell, Kevin wrote:

>I'm pulling a list of numbers from MS Excel, but occasionally if there
>is no data from excel, the value is an asterisk, but I need to make it
>What is the best way to do that?  Thus far, I'm using:
>for value in myRange:
>       try:
>           intV = int(value)
>           print intV
>       except:
>           print "its an asterisk" 
I'm affraid I did not understand what is your real problem.
Here is an answer, anyway.

When converting a string intoto an int, you should use TypeError to trap 
type errors only:

  intV = int(value)
except TypeError:
  intV = None

print intV # It will be None if 'value' is not an int



More information about the Python-list mailing list