In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to write the practical application code related to Python embedding. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
If you want to embed Python in Cmax Candle + is a relatively simple thing, what you need is to add Python's include file directory and lib file directory in VC. The following is the specific introduction of how to embed Python into Cmax Candle +. I hope you will learn a lot from it.
Under VC6.0, open tools- > options- > directories- > show directories for, add the inlude directory under the Python installation directory to the inlude files entry, and add the libs directory to the library files entry.
Under VC2005, open tools- > options- > Project and Solutions-> VC++ directory, and do the same thing.
The code is as follows:
There was an error in the execution under debug, "the python31_d.lib file could not be found". It was found later that the reason for generating under debug is that there must be a python31_d.lib file, otherwise it can only be generated under release.
# include int main () {Py_Initialize (); PyRun_SimpleString ("Print'hi, pythonium'"); Py_Finalize (); return 0;}
The prototype of Py_Initialize function is: void Py_Initialize ()
This function must be used when embedding Python in Candlespace +, which initializes the Python interpreter and must be called before using any other Python/C API. You can use the Py_IsInitialized function to determine whether the initialization is successful and return True successfully.
The prototype PyRun_SimpleString function is int PyRun_SimpleString (const char * command), which is used to execute a piece of Python code.
Note: do you need to maintain indentation between statements?
The prototype of the Py_Finalize function is void Py_Finalize (), which is used to close the Python interpreter and release the resources occupied by the interpreter.
The PyRun_SimpleFile function can be used to run the ".py" script file. The function prototype is as follows:
Int PyRun_SimpleFile (FILE * fp, const char * filename)
Where fp is the open file pointer and filename is the file name of the python script to run. However, because the function is officially released and compiled by visual studio 2003.NET, if you use another version of the compiler, the FILE definition may crash due to the version. At the same time, you can replace the function in the following ways for simplicity:
PyRun_SimpleString ("execfile ('file.py')"); / / use execfile to run python files
Use Python script to convert to windows executable program
Functions that are often used when writing shell scripts in Python
Introduction of files commonly used in writing shell scripts by Python
Three things that Python scripts often encounter when debugging with gdb
The call relationship between the functions within the Python script
Py_BuildValue () is used to convert numbers and strings to the corresponding data types in Python (in C language, all Python types are declared as PyObject types). The function prototype is as follows:
PyObject * Py_BuildValue (const char * format, … .)
PyString_String () is used to convert variables of type PyObject* into char* types that the C language can handle. The specific prototypes are as follows:
Char* PyString_String (PyObject * p)
The above is the editor for you to share the Python embedded Cmax Cellular + related practical application code how to write, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.