看板 Python 關於我們 聯絡資訊
今天看到套件章節 有一個地方不是很懂, 有人可以解惑嗎?謝謝 ---------------------------------- \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
eight0: 沒跳 cannot import name 'source' 嗎 11/12 12:59
uranusjr: 要把 __pycache__ 砍掉才看得出差異,不然會 cache 11/12 14:42
GooLoo: 資料夾整個?還是裡面__init__.cpython-35 11/12 17:23
※ 編輯: GooLoo (114.25.181.127), 11/12/2016 17:34:54
uranusjr: 理論上只要 __init__.cpython-35 就好, 但都砍掉也沒差 11/12 20:43