import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
math.sqrt后面居然不用跟()
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
math.sqrt后面居然不用跟()
2017-11-15
服务器文件被改了:
import os
print os.getcwd()
print os.listdir(r'/data/webroot')
print os.listdir(r'/data/webroot/conf')
print os.path.isdir(r'/data/webroot/conf')
print os.path.isfile(r'/data/webroot/conf/app.conf')
import os
print os.getcwd()
print os.listdir(r'/data/webroot')
print os.listdir(r'/data/webroot/conf')
print os.path.isdir(r'/data/webroot/conf')
print os.path.isfile(r'/data/webroot/conf/app.conf')
2017-11-14
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2017-11-14
def cmp_ignore_case(s1, s2):
a1 = s1.lower()
a2 = s2.lower()
if a1 > a2:
return 1
if a1 < a2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'],cmp_ignore_case)
a1 = s1.lower()
a2 = s2.lower()
if a1 > a2:
return 1
if a1 < a2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'],cmp_ignore_case)
2017-11-14
print filter(lambda s:s and len(s.strip())>0, ['test', None, '', 'str', ' ', 'END'])
2017-11-14
def cmp_ignore_case(s1, s2):
if s1[0:1].lower() > s2[0:1].lower():
return 1
else :
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0:1].lower() > s2[0:1].lower():
return 1
else :
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-11-14
def performance(unit):
def performance_decorator(f):
def wrapper(*args,**kw):
t1 = time.time() r = f(*args,**kw) t2 = time.time()
print 'call %s in %s %s'%(f.__name__,t2-t1,unit)
return r
return wrapper
return performance_decorator
def performance_decorator(f):
def wrapper(*args,**kw):
t1 = time.time() r = f(*args,**kw) t2 = time.time()
print 'call %s in %s %s'%(f.__name__,t2-t1,unit)
return r
return wrapper
return performance_decorator
2017-11-14
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2017-11-14
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2017-11-14
class Person(object):
count = 0
def __init__(self, name):
self.name = name
Person.count += 1
count = 0
def __init__(self, name):
self.name = name
Person.count += 1
2017-11-14