@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
2015-04-20
import math
def is_sqr(x):
for i in range(1,11):
if x == (i*i):
return True
print filter(is_sqr, range(1, 101))
def is_sqr(x):
for i in range(1,11):
if x == (i*i):
return True
print filter(is_sqr, range(1, 101))
2015-04-20
def format_name(s):
return s[0].upper()+s[1:len(s)].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:len(s)].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-04-20
class Person(object):
count=0
def __init__(self,name):
#self.name=name
Person.count=Person.count+1
count=0
def __init__(self,name):
#self.name=name
Person.count=Person.count+1
2015-04-20
class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda x,y:cmp(x.name,y.name))
print L2[0].name
print L2[1].name
print L2[2].name
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda x,y:cmp(x.name,y.name))
print L2[0].name
print L2[1].name
print L2[2].name
2015-04-20
class Person(object):
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
2015-04-20
try:
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
2015-04-19
import os
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
2015-04-19
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'])
2015-04-17
import time
def performance(unit):
def performance_d(f):
def fn(*args,**kw):
print 'call [%s] in %s (%s)' % (f.__name__,time.time(),unit)
return f(*args,**kw)
return fn
return performance_d
def performance(unit):
def performance_d(f):
def fn(*args,**kw):
print 'call [%s] in %s (%s)' % (f.__name__,time.time(),unit)
return f(*args,**kw)
return fn
return performance_d
2015-04-17