[問題] spyder import py檔問題

看板Python作者 (小刀會序曲)時間6年前 (2019/02/03 00:41), 6年前編輯推噓3(302)
留言5則, 3人參與, 6年前最新討論串1/1
大家好,小弟我有一個A.py檔 裡面有自己定義f函數 但在B.py import A 時,都說找不到module 'A' has no attribute 'f' A有引用進去,但內容就是讀不到,請問是為甚麼呢? A.py def f(x): return x + 2 B.py import A result=A.f(5) module 'A' has no attribute 'f' 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.36.81.206 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1549125682.A.306.html HenryLiKing: print(dir(A))呢? 請問印出來之後要做甚麼步驟ㄋ~ 02/03 01:59

02/03 02:09, 6年前 , 1F
from b import f
02/03 02:09, 1F

02/03 03:13, 6年前 , 2F
不知道是否是這問題? https://goo.gl/35WpbD
02/03 03:13, 2F
這個也不行~~謝謝 ※ 編輯: disney82231 (114.44.51.194), 02/03/2019 16:20:14

02/04 00:25, 6年前 , 3F
__init__.py
02/04 00:25, 3F

02/04 15:23, 6年前 , 4F
我用Terminal重製你的code可行
02/04 15:23, 4F

02/04 15:23, 6年前 , 5F
你是用IDE的console嗎?
02/04 15:23, 5F
文章代碼(AID): #1SLSWoC6 (Python)
文章代碼(AID): #1SLSWoC6 (Python)