[問題] __init__.py
今天看到套件章節
有一個地方不是很懂, 有人可以解惑嗎?謝謝
----------------------------------
\test.py
from source import test1,test2
print(test1.get_list())
print(test2.get_list())
----------------------------------
source\test1.py
def get_list():
list = [1,2,3]
return (list)
----------------------------------
source\test2.py
def get_list():
list = [4,5,6]
return (list)
----------------------------------
在命令提示字元
C:\Python3>python test.py
[1, 2, 3]
[4, 5, 6]
問題:
書中提到
"須要在source目錄中放一個 __init__.py的檔案
它可以是空的,python才可以將容納的目錄視為套件"
但是, 建與沒建, 都可以得到正確的結果,
我看不出 有它/沒它 的差別.....
有人知道嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.181.127
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1478921069.A.698.html
推
11/12 12:59, , 1F
11/12 12:59, 1F
→
11/12 14:42, , 2F
11/12 14:42, 2F
→
11/12 17:23, , 3F
11/12 17:23, 3F
※ 編輯: GooLoo (114.25.181.127), 11/12/2016 17:34:54
→
11/12 20:43, , 4F
11/12 20:43, 4F