另一個類對象我有一個程序名「new.py」與「:訪問通過進口
class hello:
def __init__(self, summary):
self.summary = summary
def hi(self):
print self.summary
if __name__ == "__main__":
h = hello(summary = "this is a hello program")
h.hi()
當我要進入功能喜到另一個程序名稱another.py,那麼我不能夠訪問功能..請幫助我,糾正我也... another.py:
import new
class another:
def __init__(self, value):
self.value = value
def show(self):
print "value is %s" % self.value
new.hi()
print "done"
if __name__ == "__main__":
a = another(value = "this is a another value")
a.show()
OUTPUT:
new.hi()
AttributeError: 'module' object has no attribute hi
您需要在'another.py'中定義'hello'的實例。 'new.hi'沒有定義,但是'new.hello'。 – Alex
對不起,但仍然顯示錯誤:全球名稱「新」未定義「...我試圖從新導入你好 –