gpt4 book ai didi

Python 缩进错误 : unexpected indent

转载 作者:IT老高 更新时间:2023-10-28 22:16:49 35 4
gpt4 key购买 nike

这是我的代码...我收到缩进错误,但我不知道为什么会发生。

->

# loop
while d <= end_date:
# print d.strftime("%Y%m%d")
fecha = d.strftime("%Y%m%d")
# set url
url = 'http://www.wpemergencia.omie.es//datosPub/marginalpdbc/marginalpdbc_' + fecha + '.1'
# Descargamos fichero
response = urllib2.urlopen(url)
# Abrimos fichero
output = open(fname,'wb')
# Escribimos fichero
output.write(response.read())
# Cerramos y guardamos fichero
output.close()
# fecha++
d += delta

最佳答案

运行你的程序

python -t script.py

如果您有混合制表符和空格,这将警告您。

在 *nix 系统上,您可以通过运行查看选项卡的位置

cat -A script.py

您可以使用命令自动将制表符转换为 4 个空格

expand -t 4 script.py > fixed_script.py

PS。确保在编程时使用编程编辑器(例如 emacs、vim),而不是文字处理器。使用编程编辑器不会遇到这个问题。

PPS。对于 emacs 用户,M-x whitespace-mode 将在 emacs 缓冲区中显示与 cat -A 相同的信息!

关于Python 缩进错误 : unexpected indent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634700/

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