半只蚂蚁 发表于 2017-4-27 09:36:18

python 深入学习1

  python 深入学习1
  


def ConnStr(dic):
'''build a connection string from a dictionary of parameters
return strings'''
return ";".join([" %s ==> %s" %(key, val) for key, val in dic.items()])
def fun1():
print "hello, andylin";
def fun2():
'''fun2....'''
return 0;

if "__main__" == __name__:
dic = {'a' : 'aaa',
'b' : 'bbb',
'c' : 'ccc',
'd' : 'ddd',
'e' : 'eee'};
print ConnStr(dic);

  


def Info(obj, nSpace = 10, nColl = 1):
'''Print Methones and doc strings...
Takes module, class, list, dictionary, or string.'''
lsMethod = [ fun for fun in dir(obj) if callable(getattr(obj, fun)) ]
RunFun = nColl and (lambda s: " ".join(s.split())) or (lambda s: s)
print "run fun...", RunFun;
print "\n".join(["%s%s" %(fun.ljust(nSpace), RunFun(str(getattr(obj, fun).__doc__))) for fun in lsMethod]);
if "__main__" == __name__:
print Info.__doc__
import test10
Info(test10, 5, 1);

 
页: [1]
查看完整版本: python 深入学习1