python 2.7 shell 中的缩进错误
Indentation error in python 2.7 shell
嗨,当我在 python shell 中复制这个完整的片段时,出现缩进错误
import heapq
dict = {4: 'four', 1 : 'one', 3: 'third', 2: 'two', 5:'five'}
h = []
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
a = heapq.heappop(h)
print a,' ',dict[a]
但是如果我复制第一个块
import heapq
dict = {4: 'four', 1 : 'one', 3: 'third', 2: 'two', 5:'five'}
h = []
for value in dict:
heapq.heappush(h, value)
回车然后复制第二块
for i in range(len(h)):
a = heapq.heappop(h)
print a,' ',dict[a]
点击回车,一切正常
请指导发生缩进问题的地方。
当您粘贴序列时:
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
自动缩进导致:
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
因此你的问题。
嗨,当我在 python shell 中复制这个完整的片段时,出现缩进错误
import heapq
dict = {4: 'four', 1 : 'one', 3: 'third', 2: 'two', 5:'five'}
h = []
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
a = heapq.heappop(h)
print a,' ',dict[a]
但是如果我复制第一个块
import heapq
dict = {4: 'four', 1 : 'one', 3: 'third', 2: 'two', 5:'five'}
h = []
for value in dict:
heapq.heappush(h, value)
回车然后复制第二块
for i in range(len(h)):
a = heapq.heappop(h)
print a,' ',dict[a]
点击回车,一切正常
请指导发生缩进问题的地方。
当您粘贴序列时:
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
自动缩进导致:
for value in dict:
heapq.heappush(h, value)
for i in range(len(h)):
因此你的问题。