[英]How can I count the lines of code in a project using PyCharm on Windows?
如何在 Windows 10 上使用 PyCharm 計算項目中的代碼行數?
我不是管理員,因此無法安裝新程序。
因此,我正在尋找一種利用 Windows 10 控制台的方法,或者最好是 PyCharm 中的某些功能。
我知道包pygount
可以解決我的問題。 但是我只有 anaconda 可用,並且不確定如何在這台機器上通過 pip 輕松安裝軟件包。
你可以直接使用這個函數:
import os
def countlines(start, lines=0, header=True, begin_start=None):
if header:
print('{:>10} |{:>10} | {:<20}'.format('ADDED', 'TOTAL', 'FILE'))
print('{:->11}|{:->11}|{:->20}'.format('', '', ''))
for thing in os.listdir(start):
thing = os.path.join(start, thing)
if os.path.isfile(thing):
if thing.endswith('.py'):
with open(thing, 'r') as f:
newlines = f.readlines()
newlines = len(newlines)
lines += newlines
if begin_start is not None:
reldir_of_thing = '.' + thing.replace(begin_start, '')
else:
reldir_of_thing = '.' + thing.replace(start, '')
print('{:>10} |{:>10} | {:<20}'.format(
newlines, lines, reldir_of_thing))
for thing in os.listdir(start):
thing = os.path.join(start, thing)
if os.path.isdir(thing):
lines = countlines(thing, lines, header=False, begin_start=start)
return lines
請在此處查看統計擴展
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.