def validate_dpi(s):
 if (s == u'figure'):
  return s
 try:
  return float(s)
 except ValueError:
  raise ValueError((u'"%s" is not string "figure" or could not convert "%s" to float' % (s, s)))

def validate_dpi ( s ) : if ( s == u'figure' ) : return s try : return float ( s ) except ValueError : raise ValueError ( ( u'"%s" is not string "figure" or could not convert "%s" to float' % ( s , s ) ) )
confirm s is string figure or convert s to float or raise .