2011-10-02 40 views
-4

我一直在努力的練習中加入的Python:新手Class對象PRAC和__main__

if __name__ == '__main__': 

到模塊的末尾測試我的模塊。這個想法是將該模塊作爲腳本運行,並獲得輸出 ,並能夠從其他腳本或交互式Python會話中導入該模塊。

我使用Python 2.6.6

這裏是整個代碼

class Prac: 
    ''' 
    This module is a practice in creating a main within a module. 
    ''' 

    def Fun(self): 
     print "testing function call" 


if __name__ == ' __main__': 
    Fun() 
+0

感謝伊格納西奧....咄......忘了實例化對象。將再次嘗試併發布 – wbg

+0

這次是什麼困擾? –

+0

好吧,它看起來像你有工作代碼...你有問題要去嗎? –

回答

1

這不是一個功能,它是一種方法。您需要從對象中調用該方法。

p = Prac() 
p.Fun() 

Read this.

+0

我嘗試從交互式會話調用方法,但得到了TypeError:'模塊'對象不可調用 – wbg