我想从math
中导入atan
和degree
,并将它们重命名。
我尝试使用以下代码:
from math import atan,degree as t,z
但这会导致 ImportError: cannot import name 'z'
。
我进行了多次谷歌搜索,搜索词为“导入多个模块并重命名”,但都没有结果。Python手册也没有帮助——导入页面没有解释这一点(据我所知)。
我怎样才能从一个模块中导入多个项目,并将它们重命名?
我想从math
中导入atan
和degree
,并将它们重命名。
我尝试使用以下代码:
from math import atan,degree as t,z
但这会导致 ImportError: cannot import name 'z'
。
我进行了多次谷歌搜索,搜索词为“导入多个模块并重命名”,但都没有结果。Python手册也没有帮助——导入页面没有解释这一点(据我所知)。
我怎样才能从一个模块中导入多个项目,并将它们重命名?
as
:from math import atan as t, degree as z
import
语句的描述中,它说:
import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )*
| "from" relative_module "import" identifier ["as" name]
( "," identifier ["as" name] )*
| "from" relative_module "import" "(" identifier ["as" name]
( "," identifier ["as" name] )* [","] ")"
| "from" module "import" "*"
"from" relative_module "import" identifier ["as" name]
( "," identifier ["as" name] )*
简而言之,对于您提供的例子,这意味着法律声明为:
from math import atan as t, degree as z