python - 为什么我们需要在python中使用“as”来导入
问题描述
来自 python 文档:
import_stmt: "import" module ["as" name] ("," module ["as" name] )*
| "from" module "import" identifier ["as" name]
("," identifier ["as" name] )*
| "from" module "import" "*"
module: (identifier ".")* identifier
为什么我们需要为库定义别名?
解决方案
有几个场合。
避免名称冲突
from bisect import bisect
from homework import bisect as my_bisect
# TODO: test if the two functions works similarly
避免长名称
import tensorflow as tf
制作表情包
import keras as tf
推荐阅读
- c - C 中的命名管道丢失信息
- c++ - 我编写了一个简单的矢量程序,在其中我得到了以下输出。你能帮我理解它的输出吗?
- video - FFmpeg:如何在视频底部添加阴影覆盖?
- php - 如何将一个数组添加到另一个数组
- sharepoint - Sharepoint 列表中的附加图像必须发送到电子邮件、Ms Teams、Kaizala
- flutter - Flutter SharedPreferences getInstance 返回 null
- python-3.x - 如何在 odoo 11 中使用函数标签强制修改 product_price 的值?
- reactjs - 开玩笑地在 useEffect 中测试restapi
- html - h1 标题标题没有响应我的网站
- javascript - 在博客中将谷歌字体添加到我的博客时,我在标题部分出现错误