PYTHON中的函式指標呼叫的一種方法

2021-06-15 21:09:16 字數 657 閱讀 5998

class  test:

eventmethods_test1 = 1

eventmethods_test2 = 2

eventmethods_test3 = 3

def __init__( self ):

self.initeventmethods()

self.eventmethods[1]()

def initeventmethods(self):

self.eventmethods =

def eventmethods_func1(self):

print "use the eventmethods_func1111"

def eventmethods_func2(self):

print "use the eventmethods_func2222"

def eventmethods_func3(self):

print "use the eventmethods_func3333"

這個只是個說明性的例子,各位看客,試過以後,有什麼心得,也要告訴我阿!

這種方式對於那些相同構造但是不同功能的方法效率很好,也非常方便,大規模的並列訊息的處理很有用。

是在寫c++的函式指標的時候想起來的,呵呵!可能早就有了,不過些出來玩玩而已,見笑了!

python中函式與函式之間的呼叫

1 python函式基礎 函式名 fun 函式體 1 3行 返回值 2 呼叫函式 fun 只有見到這個括號 程式會根據函式名從記憶體中找到函式體,然後執行它 2.函式的執行順序 下面的fun將上面的fun覆蓋掉了,因此,在python中 的放置位置是有要求的,不能隨意擺放,函式體要放在被呼叫的語句之...

使用shell呼叫python中的函式

最近遇到乙個需求,需要通過shell呼叫python中的乙個函式,發現其實也挺簡單的 python指令碼如下 test.py import configparser config configparser.configparser config.read test.conf def get foo ...

python 中呼叫c 定義的函式

上網搜了一下,發現在python 中呼叫c 中函式,網上大部分方法都是將c 編成.dll windows下 或者.so linux下 這樣和我們現在的需求不一致,c 寫的程式是要一直執行,當python指令碼中的httpserver接收到特定的請求再呼叫c 的函式。現在我們就不將c 定義的函式編成....