作者disney82231 (小刀會序曲)
看板Python
標題[問題] spyder import py檔問題
時間Sun Feb 3 00:41:18 2019
大家好,小弟我有一個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
推 jiyu520: from b import f 02/03 02:09
這個也不行~~謝謝
※ 編輯: disney82231 (114.44.51.194), 02/03/2019 16:20:14
推 twoboy: __init__.py 02/04 00:25
推 alex13587: 我用Terminal重製你的code可行 02/04 15:23
→ alex13587: 你是用IDE的console嗎? 02/04 15:23