- 论坛徽章:
- 0
|
请教 python 的代码错误在哪里?
# 以下是统计程序代码行数的代码
# 我的目的是统计 d:\ywgl2 下,所有的 *.ini,*.bas,*.frm 的文件总行数,
# 但是有一个问题,
# Traceback (most recent call last):
#File "D:/ywgl2/a2.py", line 13, in <module>
# data = f.read()
# UnicodeDecodeError: 'gbk' codec can't decode bytes in position 598-599: illegal multibyte sequence
# 不知以上提示是什么意思?
import os
lines_count = 0
for roots,dirs,files in os.walk('d:/ywgl/'):
for file in files:
if file[-4:]=='.ini' or file[-4:]=='.bas':
f = open(os.path.join(roots, file))
data = f.read()
f.close()
lines_count += data.count('\n')
print ("all lines count:%d" %lines_count) |
|