小编Dzr*_*gle的帖子

缩进的4个空格 - 语法错误

我使用4个空格进行缩进,但是出现语法错误.当我在文本编辑器中使用缩进时,工作正常.文本编辑器只创建一个块,我无法编辑它.空间不能用作缩进吗?

def replace_line(file_name, line_num, text):
    try:
            lines = open(file_name, 'r').readlines()
            lines[line_num] = text
            out = open(file_name, 'w')
            out.writelines(lines)
            out.close()
        if not var and not var2:
            return
Run Code Online (Sandbox Code Playgroud)

我在if not var行上得到了语法错误.

python indentation

1
推荐指数
1
解决办法
93
查看次数

标签 统计

indentation ×1

python ×1