def num2num(num):
 if (isinstance(num, LongType) and (num < sys.maxint)):
  return int(num)
 else:
  return num

def num2num ( num ) : if ( isinstance ( num , LongType ) and ( num < sys . maxint ) ) : return int ( num ) else : return num
converts long to int if small enough to fit .