您正在混合制表符和空格:>>> from pprint import pprint
>>> pprint('''
... tweet_text = "Raspberry Pi server is DOWN!"
... textfile = open('/root/Documents/server_check.txt','w')
... '''.splitlines())
['',
' tweet_text = "Raspberry Pi server is DOWN!"',
"\ttextfile = open('/root/Documents/server_check.txt','w')"]
注意第二行开头的\t,但第一行有4个空格。在
Python将制表符展开到下一个第8列,它超过了第一行中的4个空格。所以第二行缩进到两个缩进级别,而第一行只缩进一个级别。在Spaces are the preferred indentation method.
以及Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.
因为要正确配置标签页,而不是不小心在几个空格中混合而弄脏缩进是很困难的。在
将编辑器配置为在编辑时将制表符转换为空格;这样,您仍然可以使用制表符键盘键而不会落入此陷阱。在