Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使这个脚本循环,直到python没有错误为止?_Python_Tweepy - Fatal编程技术网

如何使这个脚本循环,直到python没有错误为止?

如何使这个脚本循环,直到python没有错误为止?,python,tweepy,Python,Tweepy,我试图使这个脚本循环,直到没有错误,但我对python非常陌生,只是不断遇到错误 我已经尝试了我所知道的一切,但这对我来说不是一件容易的任务 def更改屏幕名称自己: 正在尝试更改。。。 尝试: status=self.api.update\u profilescreen\u name=name printName已更新! 除tweepy.TweepError作为错误外: resp=error.response.json[errors][0] printName不可用。 打印{}{}.forma

我试图使这个脚本循环,直到没有错误,但我对python非常陌生,只是不断遇到错误

我已经尝试了我所知道的一切,但这对我来说不是一件容易的任务

def更改屏幕名称自己: 正在尝试更改。。。 尝试: status=self.api.update\u profilescreen\u name=name printName已更新! 除tweepy.TweepError作为错误外: resp=error.response.json[errors][0] printName不可用。 打印{}{}.formatresp[message],resp[code] 最后: 回归自我 预期结果是继续尝试相同的名称更改,直到没有错误,但它当前只尝试一次,然后停止

def change_screen_name(self):
    while True:
        print("Attempting change...")
        try:
            status = self.api.update_profile(screen_name="name")
            print("Name updated!")
            return self
        except tweepy.TweepError as error:
            resp = error.response.json()["errors"][0]
            print("Name unavailable.")
            print("{} ({})".format(resp["message"], resp["code"]))
我有一个无限循环在运行

2一旦你的尝试成功,打破无限循环


3在try/except之后最终运行。如果您有finally语句,它将始终运行。

什么错误?请更精确一点,无论它是在try中工作还是出现异常,最终都会执行。