Bryan,

How about checking your input to see if they are digits or not?
>>> input_data = '123ABC'
>>> print input_data.isdigit()
False
>>> input_data = '1234567889'
>>> print input_data.isdigit()
True
>>> input_data = '123ABC'
>>> print input_data.isdigit()
False

or something like:

while INPUT.has_key('ReferencePositionX').isdigit() =='True':
    refx = float(INPUT['ReferencePositionX'])/10
    refy = float(INPUT['ReferencePositionY'])/10
    refz = float(INPUT['ReferencePositionZ'])/10



Steve

On Jul 30, 2008, at 6:43 PM, Bryan Fodness wrote:

I am populating a dictionary from an input file, and would like to create an error code if a string is sent to a variable that expects a float or int.

INPUT = {}
for line in open(infile):
    input_line = line.split(' = ')
    INPUT[input_line[0].strip()] = input_line[1].strip()

if INPUT.has_key('ReferencePositionX'):
    refx = float(INPUT['ReferencePositionX'])/10
    refy = float(INPUT['ReferencePositionY'])/10
    refz = float(INPUT['ReferencePositionZ'])/10

I have many variables of different types, and I want to do a check in case something like ReferencePositionX = abc occurs.

--
"The game of science can accurately be described as a never-ending insult to human intelligence." - João Magueijo
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to