2014-10-24 6 views
0

SublimeREPL에서 일부 Python 명령을 평가하려고하지만 모든 새로운 명령으로 인해 IndentationError가 발생합니다. 한 번에 한 줄씩 보내면 코드가 작동합니다. 나는 일부 라인 주석 문자를 넣어 경우 여기 Python 들여 쓰기 오류 : SublimeREPL을 사용하는 숭고한 텍스트 2

는 ... 그러나

로 평가
class Array(object): 
    def __init__(self, length = 0, baseIndex = 0): 
     assert(length >= 0) 
     self._data = [0 for i in range(length)] 
     self._baseIndex = baseIndex 
    def __copy__(self): 
     result = Array(len(self._data)) 
     for i, datum in enumerate(self._data): 
      result._data[i] = datum 
     result._baseIndex = self._baseIndex 
     return result 
    def __len__(self): 
     return len(self._data) 

...

IndentationError: unexpected indent 
>>> class Array(object): 
...  def __init__(self, length = 0, baseIndex = 0): 
...   assert(length >= 0) 
...   self._data = [0 for i in range(length)] 
...   self._baseIndex = baseIndex 
... 
>>>  def __copy__(self): 
    File "<stdin>", line 1 
    def __copy__(self): 
    ^
IndentationError: unexpected indent 
>>>   result = Array(len(self._data)) 
    File "<stdin>", line 1 
    result = Array(len(self._data)) 
    ^
IndentationError: unexpected indent 
>>>   for i, datum in enumerate(self._data): 
    File "<stdin>", line 1 
    for i, datum in enumerate(self._data): 
    ^
IndentationError: unexpected indent 
>>>    result._data[i] = datum 
    File "<stdin>", line 1 
    result._data[i] = datum 
    ^
IndentationError: unexpected indent 
>>>   result._baseIndex = self._baseIndex 
    File "<stdin>", line 1 
    result._baseIndex = self._baseIndex 
    ^
IndentationError: unexpected indent 
>>>   return result 
    File "<stdin>", line 1 
    return result 
    ^
IndentationError: unexpected indent 
>>> 
>>>  def __len__(self): 
    File "<stdin>", line 1 
    def __len__(self): 
    ^
IndentationError: unexpected indent 
>>>   return len(self._data) 
    File "<stdin>", line 1 
    return len(self._data) 
    ^
IndentationError: unexpected indent 

예에서 시도이다는 제외하고 잘 작동 각 줄 앞에 후행 "... ... ... ..."에 대해

class Array(object): 
    def __init__(self, length = 0, baseIndex = 0): 
     assert(length >= 0) 
     self._data = [0 for i in range(length)] 
     self._baseIndex = baseIndex 
# 
    def __copy__(self): 
     result = Array(len(self._data)) 
     for i, datum in enumerate(self._data): 
      result._data[i] = datum 
     result._baseIndex = self._baseIndex 
     return result 
# 
    def __len__(self): 
     return len(self._data) 
# 

보내진 후 나는 REPL 창을 클릭하고 "... ... ... ..."이라는 줄을 입력하여 평가를 받으십시오.

>>> class Array(object): 
    def __init__(self, length = 0, baseIndex = 0): 
     assert(length >= 0) 
     self._data = [0 for i in range(length)] 
     self._baseIndex = baseIndex 
# 
    def __copy__(self): 
     result = Array(len(self._data)) 
     for i, datum in enumerate(self._data): 
      result._data[i] = datum 
     result._baseIndex = self._baseIndex 
     return result 
# 
    def __len__(self): 
     return len(self._data) 
# 
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 

나는 매우 단순한 것이 누락되면 사과드립니다. 나는이 답을 어디에서나 찾아 보았습니다.

답변

0

실제로 실행중인 코드와 다른 코드를 표시 한 것으로 의심됩니다. 실제 파이썬 스크립트에서는 def의 각 부분을 서로 구분하는 몇 줄의 개행을 가졌지 만 여기에는 붙여 넣은 코드 섹션에 나와 있지 않습니다. 어쩌면 여기에 서식 문제가 있기 때문일 수도 있습니다.

그러나 파이썬에서 빈 줄은 이전 섹션으로 끝났음을 나타냅니다. 대화 형 인터프리터 (SublimeREPL과 같은)를 사용할 때만 중요합니다. 공백과 들여 쓰기가 중요합니다. 이 경우 텍스트를 인터프리터로 전송하는 것입니다. 인터프리터는 텍스트를 잘라내어 붙여 넣기 만하면됩니다. def __copy__(self) 전에 개행을보고, 그 클래스 정의를 평가한다고 가정합니다. 그런 다음 def __copy__(self)을보고 약간의 들여 쓰기 공간이 있음을 알았습니다. 이로 인해 수신중인 IndentationError이 발생합니다.

SublimeREPL의 github 계정에서 already existing bug에 대한 의견을 보내거나 코드에 빈 줄을 사용하지 마십시오.

관련 문제