我有以下的代码,简单的我知道(请随时提出改进建议)总计似乎是错误
这似乎与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