为什么我会得到“预期缩进的块"?当我尝试运行我的Python脚本时? [英] Why do I get "expected an indented block" when I try to run my Python script?
本文介绍了为什么我会得到“预期缩进的块"?当我尝试运行我的Python脚本时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一个错误,提示预期缩进块" 您能否指导我如何处理此错误.谢谢:)
I have an error which says "expected an indented block" Could you please guide me on how to deal with this error. Thank you:)
代码示例:
for ch in f: ( translatedToken = english_hindi_dict[ch] ) if (ch in english_hindi_dict) else (translatedToken = ch)
推荐答案
您可能会将制表符与空格混在一起.它看上去是 缩进的,但实际上不是.
You are probably mixing tabs with spaces. It looks indented but it really isn't.
您的代码给了我一个不同的错误:
Your code gives me a different error:
for ch in f: \
( translatedToken = english_hindi_dict[ch] ) \
if (ch in english_hindi_dict) else (translatedToken = ch)
↑
SyntaxError: invalid syntax
也许你是说:
for ch in f:
if ch in english_hindi_dict:
translatedToken = english_hindi_dict[ch]
else:
translatedToken = ch
也许您是说:
for ch in f:
translatedToken = english_hindi_dict[ch] if ch in english_hindi_dict else ch
两者都应该运行良好,我希望第二个要比前一个更快
Both should run just fine, and I expect the second to be faster than the former
它们都可以优化为translated = str(english_hindi_dict.get(ch, ch) for ch in f)
,但这不是问题的重点.
They both can be optimized into translated = str(english_hindi_dict.get(ch, ch) for ch in f)
but that's not the point of the question.
这篇关于为什么我会得到“预期缩进的块"?当我尝试运行我的Python脚本时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文