在 python 中使用 geany 时出现意外错误

I have an unindent error while using geany with python

我正在使用 geany,但出现以下错误

  File "autoblog2.py", line 9
    htmlfile = urllib.urlopen(url)
                                 ^
IndentationError: unindent does not match any outer indentation level

这是我的代码。

import urllib
import re

symbols_list = ["aapl","spy","goog","nflx"]

i = 0
while i<len(symbols_list):
    url = 'https://uk.finance.yahoo.com/q?s='+symbols_list[i]
    htmlfile = urllib.urlopen(url)
    htmltext = htmlfile.read()
    regex = '<span id="yfs_l84_aapl">(.+?)'+symbols_list[i]'</span>'
    pattern = re.compile(regex)
    price = re.findall(pattern,htmltext)
    print 'the price of' +symbols_list[i]
    i+=1

当我 运行 在单个 url 上使用相同的代码时,我没有收到任何错误。自从用 while 循环尝试后,我才开始使用 python 2

当您使用两个编辑器编辑一个脚本时,可能会发生这种情况。 您的缩进设置可能因编辑器而异。 与另一个编辑器一起查看脚本。 如果脚本在其他编辑器中有相同的缩进,唯一的方法是删除所有缩进并重新添加它们。 我会推荐 python-idle。 它应该像口译员一样显示缩进。 祝你好运。