繁体   English   中英

如何从与保留的 function 或 Python 中的关键字同名的模块中成功导入某些内容?

[英]How do I successfully import something from a module which has the same name as a reserved function or keyword in Python?

in Python, I am trying to import the open function object from the built-in os module, but it would not let me import it as it has the same name as the built-in open function, which is used for opening files. 如何从与保留的内置函数/关键字同名的模块中导入对象/属性?

喜欢

from os import open

您可以使用as别名。

from os import open as osopen

您可以通过as作为另一个名称导入

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM