gpt4 book ai didi

python - Python 函数中的意外缩进

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:14 26 4
gpt4 key购买 nike

<分区>

我希望我的函数返回编码。用户应该导入它。但是,如果用户按下回车键,该函数应返回 windows-1250 作为默认编码。

当我运行此代码时出现错误:

if enc == '': ^ IndentationError: unexpected indent

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com