因为Python是根据缩进,检测代码块的范围,所以现在设置tab键默认为4个空格####修改ubuntu的tab缩进为4
cd /etc/vim
sudo vim vimrc
加入:
set expandtab #适应空格代替tab
set tabstop=4 #空格数为4
方法:import os.path
aa = {'txt': 0, 'py': 0, 'others':0}
def com(filePath):
try:
f = open(filePath, 'r')
cnt = 0
for line in f:
cnt +=1
print filePath + " = " + str(cnt)
return cnt
except:
return 0
#print(com('/home/sn/script/a.txt'))
def visit(arg, dirname, names):
for item in names:
path = os.path.join(dirname, item)
if os.path.isfile(path):
if len(item.split(".")) > 1:
ext = item.split(".")
if ext[1] == "txt":
aa['txt'] += com(path)
elif ext[1] == 'py':
aa['py'] += com(path)
else:
aa['others'] += com(path)
# print "------"
os.path.walk("/home/sn/script", visit, None)
print aa