数字转换函数测试

来源:互联网 发布:什么软件打开psd 编辑:程序博客网 时间:2024/06/08 02:10
def testit(func,*nkwargs,**kwargs):    try:        retval=func(*nkwargs,**kwargs)        result=(True,retval)    except Exception,diag:        result=(False,str(diag))    return resultdef test():    funcs=(int,long,float)    vals=(1234,12.34,'1234','12.34')    for eachFunc in funcs:        print '_'*20        for eachVal in vals:            retval=testit(eachFunc,                          eachVal)            if retval[0]:                print '%s(%s)='%\                      (eachFunc.__name__,'eachVal'),retval[1]            else:                print  '%s(%s)=Failed:'%\                      (eachFunc.__name__,'eachVal'),retval[1]if __name__=='__main__':    test()    

原创粉丝点击