Python代码中的IndentationError
我有一段代码,看起来缩进了,但无法运行。我得到以下错误:Python代码中的IndentationError,python,python-2.7,Python,Python 2.7,我有一段代码,看起来缩进了,但无法运行。我得到以下错误: File "./cloneRepos.py", line 16 for line in f: ^ IndentationError: expected an indented block 代码如下: def cloneRepos(dirPath,reposListFile): with open(reposListFile,'r') as f: for line in f:
File "./cloneRepos.py", line 16
for line in f:
^
IndentationError: expected an indented block
代码如下:
def cloneRepos(dirPath,reposListFile):
with open(reposListFile,'r') as f:
for line in f:
s=line.split(".git") #Splits based on .git into two halves
x=s[0].split("/") #Splits the string based on that character
repoName=x[-1] #Gets the last element in the array
repo = clone_repository(line, dirPath) # Clones a non-bare repository line is repoUrl and dirPath is repository path
print repoName
print line
我用了两个标签,而不是一个,然后它的工作!遵循w.r.t python缩进的最佳实践是什么?我们应该使用制表符还是空格?我是python新手 如果在文件中混合使用制表符和空格,可能会发生这种情况。确保所有标签都没有了。我认为标签是解决问题的标准方法follow@Zack,表示首选空格,但要遵循与任何遗留代码相同的样式。我通常更喜欢制表符而不是空格,所以如果我正在处理只有我才会用到的东西,我会使用它们。通常每个缩进有4个空格-可以是制表符或空格(大多数使用空格),但不要将两者混合使用!