【发布时间】:2015-07-01 10:01:41
【问题描述】:
我希望我的函数返回编码。用户应该导入它。但是,如果用户点击回车,该函数应返回 windows-1250 作为默认编码。
当我运行这段代码时,我得到一个错误:
如果编码 == '': ^ IndentationError: 意外缩进
def encoding_code(prompt):
"""
Asks for an encoding,
throws an error if not valid encoding.
Empty string is by default windows-1250.
Returns encoding.
"""
while True:
enc = raw_input(prompt)
if enc == '':
enc = 'windows-1250'
try:
tmp = ''.decode(enc) # Just to throw an error if not correct
except:
print('Wrong input. Try again.')
continue
break
return enc
【问题讨论】:
-
你很可能在混合制表符和空格
标签: python indentation