簡體   English   中英

Python導入空文件夾

[英]Python importing empty folder

/tmp# mkdir foobar
/tmp# python3
Python 3.4.3 (default, Nov 28 2017, 16:41:13) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foobar
>>> 

為什么 python 允許導入任何隨機(包括空)目錄? 那么,在快照上方,我是導入一個包還是一個模塊? 是的,'foobar' 是一個文件夾,但導入目標始終是一個模塊(.py 文件),不是嗎?

您無意中創建了命名空間包

這個 錯誤 ……嗯……這個特性是在 Python 3.3+ 中引入的。

詳情在PEP 420中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM