我有以下的代碼,簡單的我知道(請隨時提出改進建議)總計似乎是錯誤
這似乎與shell腳本的功能,總好像是錯的,我算22,但它是報告42,代碼有問題嗎?
import os
myPath = os.getenv("scripts")
pyCounter = 0
sqlCounter = 0
shCounter = 0
def python_scripts():
global pyCounter
for root, dirs, files in os.walk(myPath):
for file in files:
if file.endswith('.py'):
pyCounter += 1
def sql_scripts():
global sqlCounter
for root, dirs, files in os.walk(myPath):
for file in files:
if file.endswith('.sql'):
sqlCounter += 1
def sh_scripts():
global shCounter
shell_ext = ['ksh','sh','bash']
for shell in shell_ext:
for root, dirs, files in os.walk(myPath):
for file in files:
if file.endswith(shell):
shCounter += 1
python_scripts()
sql_scripts()
sh_scripts()
print ("Python : " + str(pyCounter))
print ("SQL : " + str(sqlCounter))
print ("Shell : " + str(shCounter))
在此先感謝
請用四個空格和* no *製表符縮進您的可能。 – 2012-02-27 12:05:03
'sh_scripts'中的縮進錯誤:我無法分辨出最後一行屬於哪個塊,Python也無法做到這一點。 – 2012-02-27 12:06:47
另外,如果你的問題是'sh_scripts',爲什麼你在你的代碼中包含所有其他函數?不要讓我們讀任何超出我們需要的東西。 – 2012-02-27 12:08:25