如果python脚本不执行另一个命令,如何使它执行另一个命令?

如果python脚本不执行另一个命令,如何使它执行另一个命令?,python,python-3.x,python-requests,command,Python,Python 3.x,Python Requests,Command,示例:假设我编写了如下代码:(只是一个示例) #开始 但是,假设我想实现一些东西,使脚本在代码中执行修改,例如:utf-8无法解码,如果发生这种情况,代码将更改或执行一些其他代码,而这些代码将不进行解码发送。decode(utf-8) 那就是: response = request.urlopen(url) result = response.read().decode('utf-8') print(result) 无法使用utf-8进行解码 然后代码改变了。。。或者某个命令执行它下面的代码,

示例:假设我编写了如下代码:(只是一个示例)

#开始

但是,假设我想实现一些东西,使脚本在代码中执行修改,例如:
utf-8
无法解码,如果发生这种情况,代码将更改或执行一些其他代码,而这些代码将不进行解码发送。
decode(utf-8)

那就是:

response = request.urlopen(url)
result = response.read().decode('utf-8')
print(result)
无法使用
utf-8进行解码
然后代码改变了。。。或者某个
命令执行它下面的代码,然后代码用以下命令重新执行:

result = response.read()
print (result) **#END**

这是一个示例实现,其中2个命令中的1个不起作用

def iDontWork():
    # This is a random example, where division by zero will not work.
    return 1/0

def iDoWork():
    # This is a random working method.
    return 1/1

try:
    iDontWork()
except Exception:
    iDoWork()
    print("First function (iDontWork) didn't work, so function the second function (iDoWork) started working.")

google异常处理/Try语句
def iDontWork():
    # This is a random example, where division by zero will not work.
    return 1/0

def iDoWork():
    # This is a random working method.
    return 1/1

try:
    iDontWork()
except Exception:
    iDoWork()
    print("First function (iDontWork) didn't work, so function the second function (iDoWork) started working.")