匹配外部缩进的Python缩进错误

2024-10-01 05:01:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下python代码。你知道吗

import subprocess, process_utility

class PhantomasProcessor:

    def run_test(self, url):
    """
    Method to run a test through Phantomas.

    Args:
        url for which you want to run the test.

    Returns:
         The json output for 
     """

    command = "phantomas " + url + "--har=test.har"
    result = ProcessUtility.execute_command(command)
    return result

def main():
phantomas_processor = PhantomasProcessor()
print phantomas_processor.run_test("www.amazon.com")

if __name__ == "__main__":
    main()

执行时我得到了错误。你知道吗

IndentationError: unindent does not match any outer indentation level。你知道吗

我已经匹配了外部缩进级别,但是为什么我仍然得到这个错误。你知道吗


Tags: torun代码testurlformaindef
3条回答

您的def和下面的所有行应该向右移动一个缩进(4个空格/1个制表符/您正在使用的任何内容)

在Python中,与许多其他语言不同,代码的缩进很重要。在您的例子中,您没有缩进类声明的内容:

导入子进程,进程实用程序

class PhantomasProcessor:

    def run_test(self, url):
        """
        Method to run a test through Phantomas.

        Args:
             url for which you want to run the test.

        Returns:

             The json output for 
        """

        command = "phantomas " + url + "--har=test.har"
        result = execute_command(command)
        return result

给你。你知道吗

import subprocess, process_utility

class PhantomasProcessor:

    def run_test(self, url):
    """
    Method to run a test through Phantomas.

    Args:
        url for which you want to run the test.

    Returns:
         The json output for 
     """

    command = "phantomas " + url + "--har=test.har"
    result = ProcessUtility.execute_command(command)
    return result

def main():
    phantomas_processor = PhantomasProcessor()
    print phantomas_processor.run_test("www.amazon.com")

if __name__ == "__main__":
    main()

相关问题 更多 >