UserPreferencesModel.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:PogomBOT 作者: eugenio412 项目源码 文件源码
def __dump_file(self, temp = False):

        # Clear out program data.......
        pref_loc = self.__preferences

        if temp:
            try:
                fd = tempfile.NamedTemporaryFile(dir=tempfile._get_default_tempdir(), delete=True)
            except Exception as e:
                logger.warn('[%s] Unable to create preferences temporary file. (%s)' % (self.chat_id, e))
                raise Exception("Unable to create preferences temporary file. (%s)" % e)
        else:
            # try to open preferences file
            try:
                fd = open(self.fullpath, 'w', encoding='utf-8')
            except Exception as e:
                logger.warn('[%s] Unable to open preference file for writing. (%s)' % (self.chat_id, e))
                raise Exception("Unable to open preferences file '%s." % self.fullpath)
        try:
            with fd:
                json.dump(pref_loc, fd, indent=4, sort_keys=True, separators=(',', ':'))
        except Exception as e:
            logger.error('[%s] Unable to write to preferences file. (%s)' % (self.chat_id, e))
            raise Exception("Unable to write preferences to file '%s."%self.fullpath)
        # close file
        fd.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号