Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0005还有问题,pillow不是很熟悉 #251

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unfinished: '_io.TextIOWrapper' object has no attribute 'startwith'
  • Loading branch information
ZTCooper committed Oct 9, 2017
commit 71200631b339c052a7037e1b4a6b714eb34b05a1
44 changes: 44 additions & 0 deletions ztcooper/0007/0007.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os

def count_lines(file_name):
line1 = 0
line2 = 0
space1 = 0
space2 = 0
comment1 = 0
comment2 = 0
ext = os.path.splitext(file_name)[1]
with open(file_name, encoding = 'gbk', errors='ignore') as f:
for each_line in f:
if ext == '.cpp':
line1 += 1
if not f:
space1 += 1
elif f.startwith('//'):
comment1 += 1
else:
line2 += 1
if not f:
space2 += 1
elif f.startwith('#'):
comment2 += 1

def search_file(start_dir):
os.chdir(start_dir)
files = os.listdir(os.curdir)
for file in files:
ext = os.path.splitext(file)[1]
if ext in ['.cpp', '.py']:
count_lines(file)

if os.path.isdir(file): #判断路径存在且是一个目录
search_file(file)
os.chdir(os.pardir) #返回上一级操作目录

if __name__ == '__main__':
search_file('E:\\Python')
print('共写了'+line1+'行C语言代码,其中包括'+space1+'行空格和'+comment1+'行注释。')
print('共写了'+line2+'行Python代码,其中包括'+space2+'行空格和'+comment2+'行注释。')