Skip to main content
 首页 » 编程设计

python 缩进

2025年05月04日18Terrylee

我正在尝试让这个脚本工作,但它...给我缩进错误

#!/usr/bin/env python 
import io 
 
myfile = open('stats.txt', 'r') 
dan = myfile.readline() 
print dan 
print "Your name: " + dan.split('|')[0] 
try: 
    myfile.write('blah') 
finally: 
        myfile.close() 
except IOError: 

帮忙吗?

请您参考如下方法:

Try-except-finally 语句的语法如下:

try: 
    statement 1 
except: 
    statement 2 
finally: 
    statement 3 

你做的有点不对 :) 尝试修复)

此外,正如 Herohtar 所说,交换您的 finally 和 except 语句。最后真的应该去追except了。