为什么我无法在shell中运行以下行?
>>> try:
... x = int("a lot")
... except items["error"] as e:
... # Same as except ValueError as e
... print("Couldn't convert")
错误讯息:
>>> try: ... x=int("a lot") File "<stdin>", line 2 x=int("a lot")<&>
^
IndentationError: expected an indented block
答案 0 :(得分:3)
适合我:
>>> items = {}
>>> items["error"] = ValueError
>>> try:
... x = int("a lot")
... except items["error"] as e:
... print "Couldn't convert"
...
Couldn't convert
答案 1 :(得分:0)
你的缩进是错误的。应该是:
>>> try:
... x = int("a lot")
... except items["error"] as e:
... print("Couldn't convert")