#from os.path import isdir ,isfile
import os
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
import os
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
2016-03-04
def count():
fs = []
for i in range(1, 4):
def lazy(x):
def calc():
return x * x
return calc
fs.append(lazy(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def lazy(x):
def calc():
return x * x
return calc
fs.append(lazy(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-03-04
import functools
sorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
sorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2016-03-02
请检查输出是否匹配:['about', 'bob', 'credit', 'zoo'],再试试!直接进入下一节
bug
bug
2016-03-02
import time
def performance(unit):
def x(f):
def y(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call %s() in %f %s' % (f.__name__, (t2-t1), unit)
return r
return y
return x
def performance(unit):
def x(f):
def y(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print 'call %s() in %f %s' % (f.__name__, (t2-t1), unit)
return r
return y
return x
2016-03-02
print filter(lambda s: s and len(s.strip())>0, ['test', None, '', 'str', ' ', 'END'])
2016-03-02
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-03-02