Python解釋器正確調(diào)用方式簡介
作者:佚名
Python解釋器在C語言中進行調(diào)用是實際編程中一個比較常用到的應(yīng)用技巧。在這里我們將會針對這方面的內(nèi)容進行一個詳細介紹。
如果我們想要在C語言中對Python解釋器進行調(diào)用的話,應(yīng)該如何操作呢?其實這一操作步驟還是比較簡單的。我們可以通過一下給出的代碼示例來對著一操作步驟進行充分的掌握,以幫助我們在實際應(yīng)用中獲得些幫助。
Python解釋器調(diào)用代碼示例:
- #include < iostream>
- #include < string>
- #include "Python.h"
- int main()
- {
- std::cout < < "Welcome to SIMPLEPYTHON!!" < < std::endl;
- std::cout < < "Chapter 17, Demo 01 - MUD Game Programming" < < std::endl;
- Py_Initialize(); // initialize python
- std::string str;
- std::getline( std::cin, str );
- while( str != "end" )
- {
- PyRun_SimpleString( const_cast< char*>( str.c_str() ) );
- std::getline( std::cin, str );
- }
- Py_Finalize(); // shut down python
- return 0;
- }
以上就是我們?yōu)榇蠹医榻B的有關(guān)Python解釋器的調(diào)用方法。
【編輯推薦】
責任編輯:曹凱
來源:
博客園