如何在不停止程序的情况下使用异常?

时间:2021-02-10 16:35:08

标签: python

我正在使用异常来检测泡菜文件是否存在。但是,我希望它在程序遇到该异常时立即重复而不是停止。我怎样才能做到这一点?

代码:

         try:
            print('\n > loading character...')
            w(1)
            save_game_load = save_game_name + '.pickle'
            pickle_in = open(save_game_load,"rb")
            character_save = pickle.load(pickle_in)
            print(' > character loaded successfully')
            w(0.3)
            print('\n > welcome back',character_save['name'],'!')
            print(' > here are your stats from last time: ')
            print('\n >',character_save)
        except:
            print(' > could not find a file with name',save_game_name)

0 个答案:

没有答案