[英]Python: "Indentation Error: unindent does not match any outer indentation level"
[英]Python Indentation error to match the outer indentation level
我有以下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
。
我已經匹配了外部縮進級別,但是為什么我仍然不斷收到此錯誤。
您的def和下面的所有行都應向右移動一個縮進(4個空格/ 1個制表符/所用的內容)
在Python中,與許多其他語言不同,代碼的縮進很重要。 在您的情況下,您想縮進類聲明的內容:
導入子流程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 = 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()
您需要縮進如下:
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.