Python“除了IOError:”语法错误:语法无效

时间:2016-01-19 18:36:13

标签: python

我不擅长Python,我正在尝试使这个脚本工作,并且它在'except语句'中失败了。这是代码块,它是更大脚本的一部分:

    try:  # to read the keyfile
        with open(args.keyfile, 'r') as fp:
            tmp_dict = json.load(fp)
        fp.close()
        except IOError:
            tmp_dict = {self.name: {}}
        if self.name not in tmp_dict.keys():
            tmp_dict[self.name] = {}
    # The xauth token should not be stored in clear text. encode()
    # will use the Vigenere cipher to encrypt it, using the password as
    # a key.
    tmp_dict[self.name]['xauth'] = encode(args.password, self.xauth)
    tmp_dict[self.name]['url'] = self.url
    tmp_dict[self.name]['urlbase'] = self.urlbase
    tmp_dict[self.name]['urlspan'] = self.urlspan
    tmp_dict[self.name]['last_access_time'] = self.last_access_time

这是我正在犯的错误:

  File "./zfs_session.py", line 37
except IOError:
     ^
SyntaxError: invalid syntax

由于

1 个答案:

答案 0 :(得分:1)

except需要与try处于同一缩进级别。