def performance(f):
def fn(*args, **kw):
print 'call ' + f.__name__ + '()...' + 'time is:' + time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
return f(*args, **kw)
return fn
为什么要算时间差,我这样写是对的吗,输出的时间是调用函数的时间吗?
def fn(*args, **kw):
print 'call ' + f.__name__ + '()...' + 'time is:' + time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
return f(*args, **kw)
return fn
为什么要算时间差,我这样写是对的吗,输出的时间是调用函数的时间吗?
2015-06-08
已采纳回答 / 冷雨夜2015
楼上说得对,浮点数的二进制转换造成的。浮点数在计算机中的二进制运算和整数运算不一样(具体咋计算的,我记不清的),他有一个精度的问题。两次计算出来的浮点数,精度上相等的可能性太小了。试想一下他的应用范围:随机函数就是利用这一性质,用每次产生的不同精度*N倍,就可以得到一个随机数。
2015-06-07
print isinstance(t, object)
print isinstance(t, Person)
print isinstance(t, Teacher)
print isinstance(t, Student)
答案判定条件太死板了,一定要按照tftt的顺序,tttf多整洁啊
print isinstance(t, Person)
print isinstance(t, Teacher)
print isinstance(t, Student)
答案判定条件太死板了,一定要按照tftt的顺序,tttf多整洁啊
2015-06-07
n=max(self.p,self.q)
for i in range(1,n)[::-1]:
if (self.p%i==0)and (self.q%i==0):
self.q=self.q/i
self.p=self.p/i
return '%s/%s' % (self.p,self.q)
__repr__ = __str__
for i in range(1,n)[::-1]:
if (self.p%i==0)and (self.q%i==0):
self.q=self.q/i
self.p=self.p/i
return '%s/%s' % (self.p,self.q)
__repr__ = __str__
2015-06-07
def __init__(self, num):
self.num=num
xfid=[0,1]
for n in range(1,num-1):
xfid.append(xfid[-1]+xfid[-2])
self.lst=xfid
def __str__(self):
return '%s' % self.lst
def __len__(self):
return len(self.lst)
self.num=num
xfid=[0,1]
for n in range(1,num-1):
xfid.append(xfid[-1]+xfid[-2])
self.lst=xfid
def __str__(self):
return '%s' % self.lst
def __len__(self):
return len(self.lst)
2015-06-07
class Fib(object):
def __call__(self, num):
a, b, L = 0, 1, []
for n in range(num):
L.append(a)
a, b = b, a + b
return L
f = Fib()
print f(10)
def __call__(self, num):
a, b, L = 0, 1, []
for n in range(num):
L.append(a)
a, b = b, a + b
return L
f = Fib()
print f(10)
2015-06-04
def __call__(self, num):
self.fib = []
if num == 0:
self.fib.append(0)
else:
self.fib.append(0)
self.fib.append(1)
for x in range(num-2):
self.fib.append(self.fib[x] + self.fib[x+1])
return ' '.join([str(self.fib[i]) for i in range(num)])
self.fib = []
if num == 0:
self.fib.append(0)
else:
self.fib.append(0)
self.fib.append(1)
for x in range(num-2):
self.fib.append(self.fib[x] + self.fib[x+1])
return ' '.join([str(self.fib[i]) for i in range(num)])
2015-06-04