Python except IOError SyntaxError invalid syntax

2024-05-18 12:04:42 发布

您现在位置: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

这是我得到的错误:

^{pr2}$

谢谢


Tags: thetonameinself脚本asnot