簡體   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