Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python代码中的IndentationError_Python_Python 2.7 - Fatal编程技术网

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个空格-可以是制表符或空格(大多数使用空格),但不要将两者混合使用!