gpt4 book ai didi

python "unexpected indent"

转载 作者:太空狗 更新时间:2023-10-30 03:01:29 27 4
gpt4 key购买 nike

我正在尝试运行此 python 代码,但我不断收到错误消息“意外缩进”。我不确定怎么了。间距似乎很好。有什么想法吗?

services = ['Service1']  
for service in services:
try:
print service + '\t',
if 'notavailable' not in requests.get('some website' + service + '&username=' + username, headers={'X-Requested-With': 'XMLHttpRequest'}).text:
print 'Available'
else:
print ''
except Exception as e:
print e

最佳答案

services = ['Service1'] 不符合你的 for 循环。

services = ['Service1']  
for service in services: <-- unexpected indentation

只需按如下所示排列您的代码。

services = ['Service1'] # need to line up with loop
for service in services:
try:
print service + '\t',
if 'notavailable' not in requests.get('some website' + service + '&username=' + username, headers={'X-Requested-With': 'XMLHttpRequest'}).text:
print 'Available'
else:
print ''
except Exception as e:
print e

你的代码也是 python 2 语法而不是 python 3

关于 python "unexpected indent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25100948/

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