没有学setattr(self, k, v),只有这样
class Person(object):
def __init__(self,name,gender,birth,job):
self.name=name
self.gender=gender
self.birth=birth
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
class Person(object):
def __init__(self,name,gender,birth,job):
self.name=name
self.gender=gender
self.birth=birth
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2015-07-24
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-07-24
from os.path import isdir,isfile
print isdir(r'/data/webroot/resource/python')
print isfile(r'/data/webroot/resource/python/test.txt')
print isdir(r'/data/webroot/resource/python')
print isfile(r'/data/webroot/resource/python/test.txt')
2015-07-24
感觉还不懂得来这里,讲得很清楚了
http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html
http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html
2015-07-24
def calc_prod(lst):
def lazy_prod():
n=1
for i in lst:
n*=i
return n
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
n=1
for i in lst:
n*=i
return n
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2015-07-24
#from __future__ import unicode_literals
s = u'am I an unicode?'
print isinstance(s, unicode)
s = u'am I an unicode?'
print isinstance(s, unicode)
2015-07-23
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'])
2015-07-23
def count():
fs = []
for i in range(1, 4):
fs.append(lambda x=i:x*x)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
fs.append(lambda x=i:x*x)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-07-23
print filter(lambda s: s and s.strip(), ['test', None, '', 'str', ' ', 'END'])
何必加上len > 0
何必加上len > 0
2015-07-23
def count():
return [(lambda j=i:j*j) for i in range(1, 4)]
f1, f2, f3 = count()
print f1(), f2(), f3()
虽然没看懂老师讲的,但是楼下说的我看懂了。
return [(lambda j=i:j*j) for i in range(1, 4)]
f1, f2, f3 = count()
print f1(), f2(), f3()
虽然没看懂老师讲的,但是楼下说的我看懂了。
2015-07-23