获取Python 文档字符串

bfhtian bfhtian 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
python核心编程第二版习题9-9
进入 Python 标准库所在的目录. 检查每个 .py 文件看是否有
__doc__ 字符串, 如果有, 对其格式进行适当的整理归类. 你的程序执行完毕后, 应该会生成一个
漂亮的清单. 里边列出哪些模块有文档字符串, 以及文档字符串的内容. 清单最后附上那些没有文
档字符串模块的名字.

本来是想先找到后缀为.py的文件,然后读取文件里的内容,找到""" """(windows xp下python3.0 IDLE)
代码如下:

#已经加入了import os,db为字典序列
def doc():
bpath=r'd:\program files\python\lib'
files=os.listdir(bpath)
for eachfile in files:
if os.path.splitext(eachfile)[1]=='.py':
mpath=os.path.join(bpath,eachfile)
sign='"""'
mpath.encode('utf-8','ignore')
f=open(mpath,'rb')
text=f.read()
lpos=text.find(sign)
if lpos!=-1:
rpos=text.find(sign,lpos+1)
doc=text[lpos+1:rpos]
else:
doc=''
db.setdefault(os.path.basename(eachfile),doc)
f.close()


TypeError: expected an object with the buffer interface
ps:怎样调试python程序
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
bfhtian
脚本语言 37,737 成员 34,208 内容