Python API中一些可直接調用的函數介紹
如果你在Python直接調用中你會發現很多的函數是不能被直接調用的,當然又不能直接調用的就會有在Python中直接被調用的函數,以下就是對可以直接調用的這些Python API的相關內容的介紹。
Python直接調用中會出現不直接調用的PyParser和PyTokenizer的函數,而是直接調用下面的這些Python API:
- PyAPI_FUNC(node *) PyParser_ParseString
(const char *, grammar *, int,- perrdetail *);
- PyAPI_FUNC(node *) PyParser_ParseFile
(FILE *, const char *, grammar *, int,- char *, char *, perrdetail *);
- PyAPI_FUNC(node *) PyParser_ParseStringFlags
(const char *, grammar *, int,- perrdetail *, int);
- PyAPI_FUNC(node *) PyParser_ParseFileFlags
(FILE *, const char *, grammar *,- int, char *, char *,
- perrdetail *, int);
- PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename
(const char *,- const char *,
- grammar *, int,
- perrdetail *, int);
- /* Note that he following function is defined
in pythonrun.c not parsetok.c. */- PyAPI_FUNC(void) PyParser_SetError(perrdetail *);
PyAPI_FUNC宏是用于定義公用的Python API,表明這些函數可以被外界調用。在Windows上面Python Core被編譯成一個DLL,因此PyAPI_FUNC等價于大家常用的__declspec(dllexport)/__declspec(dllimport)。
這些函數把PyParser和PyTokenizer對象的接口和細節包裝起來,使用者可以直接調用PyParser_ParseXXXX函數來使用PyParser和PyTokenizer的功能而無需知道PyPaser/PyTokenizer的工作方式,這可以看作是一個典型的Façade模式。以PyParser_ParseFile為例,該函數分析傳入的FILE返回生成的CST。其他的函數與此類似,只是分析的對象不同和傳入參數的不同。
以上就是對直接調用下面的這些Python API相關的內容的介紹,忘你會有所收獲。
【編輯推薦】