2014-11-07 4 views
0

У меня есть следующий код 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.

Я сравнил внешний уровень отступа, но почему же я все еще продолжаю получать эту ошибку.

+0

убедитесь, что вы не смесительные вкладки и пробелы. – Thedudxo

+0

Это работает для меня. Это ваш полный код? –

+0

У меня тоже есть основной класс. отредактировал код – station

ответ

0

В 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 
+0

Я пробовал то же самое, но я все равно получаю ту же ошибку – station

+0

Тогда вы должны проверить, случайно ли вы смешали вкладки и пробелы. –

+0

Нет, я не проверил это. – station

1

Ваше Защиту и все ниже строки должны быть перемещены вправо на один отступа (4 пробела/1 вкладка/все, что вы используете)

+0

Я отредактировал вопрос. Я пробовал то же самое, но все равно получаю эту ошибку – station

+0

Строки ниже 'def run_test' все еще слишком далеко влево – theodox

0

Здесь вы идете.

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() 
0

Вы должны отступа следующим образом:

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() 
Смежные вопросы