# 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