>>> help(property)
| class C(object):
| @property
| def x(self):
| "I am the 'x' property."
| return self._x
| @x.setter
| def x(self, value):
| self._x = value
| @x.deleter
| def x(self):
| del self._x
就仅仅为了不写长的函数名......
| class C(object):
| @property
| def x(self):
| "I am the 'x' property."
| return self._x
| @x.setter
| def x(self, value):
| self._x = value
| @x.deleter
| def x(self):
| del self._x
就仅仅为了不写长的函数名......
2016-03-31
def __str__(self):
return '(Student: %s, %s,%s)' % (self.name, self.gender,self.score)
__repr__=__str__
s = Student('Bob', 'male', 88)
print s.__repr__()
return '(Student: %s, %s,%s)' % (self.name, self.gender,self.score)
__repr__=__str__
s = Student('Bob', 'male', 88)
print s.__repr__()
2016-03-31
def perf_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
return f(*args,**kw)
return wrapper
return perf_decorator
@functools.wraps(f)
def wrapper(*args, **kw):
return f(*args,**kw)
return wrapper
return perf_decorator
2016-03-30
def performance(unit):
def p_fn(f):
def fn(*args,**kw):
if unit == 'ms':
t=str(datetime.datetime.now().microsecond)+'ms'
else :
t=str(time.time())+'s'
print 'call %s() in %s' % (f.__name__,t)
太长发不了
def p_fn(f):
def fn(*args,**kw):
if unit == 'ms':
t=str(datetime.datetime.now().microsecond)+'ms'
else :
t=str(time.time())+'s'
print 'call %s() in %s' % (f.__name__,t)
太长发不了
2016-03-30
def performance(f):
def fn (*args,**kw):
print 'call ' + f.__name__ + '() in',time.time()
return f(*args,**kw)
return fn
def fn (*args,**kw):
print 'call ' + f.__name__ + '() in',time.time()
return f(*args,**kw)
return fn
2016-03-30
print filter(lambda s : s and len(s.strip())>0, ['test', None, '', 'str', ' ', 'END'])
把 s 改写成 x ,输出结果一样,可是就是不能通过,真是醉了
把 s 改写成 x ,输出结果一样,可是就是不能通过,真是醉了
2016-03-30
def cmp_ignore_case(s1, s2):
if s1.upper() > s2.upper():
return 1
elif s1.upper() < s2.upper():
return -1
return 0
if s1.upper() > s2.upper():
return 1
elif s1.upper() < s2.upper():
return -1
return 0
2016-03-30
import time
def performance(unit):
def log_decorator(f):
def fn(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call'+f.__name__+'()','in',str(t2-t1)+unit
return r
return fn
return log_decorator
def performance(unit):
def log_decorator(f):
def fn(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call'+f.__name__+'()','in',str(t2-t1)+unit
return r
return fn
return log_decorator
2016-03-30
没有纠错功能,第一遍竟然把name写成mane~~~~
import time
def performance(f):
def fn(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call',f.__name__+'() in',str(t2-t1)+'s'
return r
return fn
import time
def performance(f):
def fn(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call',f.__name__+'() in',str(t2-t1)+'s'
return r
return fn
2016-03-30
def calc_prod(lst):
def chengji():
b = 1
for a in lst:
b = b * a
return b
return chengji
f = calc_prod([1, 2, 3, 4])
print f()
可以用最新学习的reduce()。开始我是忘记了,,,这记性
def chengji():
b = 1
for a in lst:
b = b * a
return b
return chengji
f = calc_prod([1, 2, 3, 4])
print f()
可以用最新学习的reduce()。开始我是忘记了,,,这记性
2016-03-30
def cmp_ignore_case(s1, s2):
t1=s1.lower()
t2=s2.lower()
if t1>t2:
return 1
if t1<t2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
t1=s1.lower()
t2=s2.lower()
if t1>t2:
return 1
if t1<t2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-03-29