Uses of Python's “from” keyword?

前端 未结 6 635
一整个雨季
一整个雨季 2021-01-11 11:53

Are there any other uses for Python\'s \"from\" keyword aside from import statements?

6条回答
  •  执念已碎
    2021-01-11 12:39

    In Python 2.x, the only use of from is for the from x import y statement. However, for Python 3.x, it can be used in conjunction with the raise statement, e.g.:

    try:
        raise Exception("test")
    except Exception as e:
        raise Exception("another exception") from e
    

提交回复
热议问题