def tryconvert(value, desired_types=SCALAR_TYPES, default=None, empty='<STR_LIT>', strip=True):
if value in tryconvert.EMPTY:<EOL><INDENT>if isinstance(value, basestring):<EOL><INDENT>return type(value)(empty)<EOL><DEDENT>return empty<EOL><DEDENT>if isinstance(value, basestring):<EOL><INDENT>if not value:<EOL><INDENT>return type(value)(empty)<EOL><DEDENT>if strip:<EOL><INDENT>value = value.strip()<EOL><DEDENT><DEDENT>if isinstance(desired_types, type):<EOL><INDENT>desired_types = (desired_types,)<EOL><DEDENT>if desired_types is not None and len(desired_types) == <NUM_LIT:0>:<EOL><INDENT>desired_types = tryconvert.SCALAR<EOL><DEDENT>if len(desired_types):<EOL><INDENT>if (isinstance(desired_types, (list, tuple)) and<EOL>len(desired_types) and<EOL>isinstance(desired_types[<NUM_LIT:0>], (list, tuple))):<EOL><INDENT>desired_types = desired_types[<NUM_LIT:0>]<EOL><DEDENT>elif isinstance(desired_types, type):<EOL><INDENT>desired_types = [desired_types]<EOL><DEDENT><DEDENT>for t in desired_types:<EOL><INDENT>try:<EOL><INDENT>return t(value)<EOL><DEDENT>except (ValueError, TypeError, InvalidOperation, InvalidContext):<EOL><INDENT>continue<EOL><DEDENT>return default<EOL><DEDENT>return default<EOL>
Convert value to one of the desired_types specified (in order of preference) without raising an exception.

If value is empty is a string and Falsey, then return the `empty` value specified.
If value can't be converted to any of the desired_types requested, then return the `default` value specified.

>>> tryconvert('MILLEN2000', desired_types=float, default='GENX')
'GENX'
>>> tryconvert('1.23', desired_types=[int,float], default='default')
1.23
>>> tryconvert('-1.0', desired_types=[int,float])  # assumes you want a float if you have a trailing .0 in a str
-1.0
>>> tryconvert(-1.0, desired_types=[int,float])  # assumes you want an int if int type listed first
-1
>>> repr(tryconvert('1+1', desired_types=[int,float]))
'None'