Python 编程核心 - Chapter9练习
2016-03-26 15:54
483 查看
# 9-8 mn = raw_input('Please Input Module Name:') module = __import__(mn) attr_list = dir(module) # print attr_list for obj in attr_list: print 'Name:', obj print 'Type:', type(getattr(module,obj)) print 'Value:', getattr(module,obj) print 'Doc:', getattr(module, obj) print
<pre name="code" class="python"># 9-9 import os PATH = r'C:\Python27\Lib' def has_doc(file_name): """ # check if the file of the module has doc string :param file_name: file name of the module, '*.py' :return: None-> No Doc string, DocString -> Has Doc String """ f_path = PATH + os.sep + file_name fh = open(f_path) content = fh.read() fh.seek(0) doc = '' if content.startswith('"""'): for eachLine in fh: doc += eachLine if eachLine.endswith('"""\n'): break return doc else: return None list_1 = [] list_2 = [] for file in os.listdir(PATH): # ignore all file other than *.py if not file.endswith('.py'): continue doc = has_doc(file) # print doc if doc is None: list_2.append(file) else: list_1.append((file, doc)) # print the result for (file_name, doc_str) in list_1: print """************************************\n%s:\n************************************\n%s\n\n""" % (file_name, doc_str) for file_name in list_2: print """************************************\n%s:\n************************************\n""" % file_name
9-10 没学GUI,暂缓
9-11
相关文章推荐
- 朴素贝叶斯算法(Naive Bayes)算法的python实现 含源代码
- python2.7;解决中文无法正常显示问题
- 安装pygraphviz遇到的问题解决办法。
- python面试题
- 动手写一个Python Web 框架学习笔记 - 相关依赖学习(2)
- python--基础学习(六)sqlite数据库基本操作
- Python学习:异步IO:协程和asyncio
- Pyhton: abs() 函数
- Python_模拟登陆新浪微博
- ubuntu下升级python
- Windows下IPython的配置安装
- Python在线笔试琐碎
- python 输出冒号;引号嵌套问题
- 中文Windows下用Python修改MAC地址
- 练习5:python的格式化字符
- 【资源汇集.转】Python 学习资源
- 17. Letter Combinations of a Phone Number
- python从零安装
- python--函数每天熟悉一个
- Python and or ?A:B