Tool ---> option ---> projectc and solutions ---> VC ++ Directories
Path of the include file that is added to the python installation directory in include files
Path of the libs folder where libraray files is added to the python installation directory
Go to the include directory of Python and find pyconfig.
Ifdef _ debug
# Pragma comment (Lib, "python27_d.lib ")
# Else
# Pragma comment (Lib, "python27.lib ")
# Endif/* _ debug */
Change python27_d.lib to python27.lib.
And save it.
# Include <python. h> using namespace STD; void main !! // System ("test. PY "); // initialize the python environment. In order to later use the C apipy_initialize () provided by Python; pyobject * pname, * pmodule, * pfunc, * pargs, * pvalue; If (! Py_isinitialized () {printf ("initialized error! \ N ") ;}// the simplest Python c api // pyrun_simplestring (" Print 'Hello world' "); // obtain the name of the Python script, reference this module. At this time, the main function of this module is executed !! Pname = pystring_fromstring ("hello"); pmodule = pyimport_import (pname); If (! Pmodule) {printf ("can not open the script! \ N ") ;}// find the defined function pfunc = pyobject_getattrstring (pmodule," hello ") in the referenced Python module "); // Method for assigning values to function parameters/* pargs = pytuple_new (1); pvalue = pystring_fromstring ("10000"); pytuple_setitem (pargs, 0, pvalue ); * // The second method for assigning values to function parameters: pargs = py_buildvalue ("(I)", 10); // call this function. The first parameter is the returned function, the second parameter is the function parameter list pyobject_callobject (pfunc, pargs); // pyobject_callobject (pfunc, null); // clear the python environment py_finalize (); // The problem encountered during this write process is: at the beginning, the C ++ project name was test_proj. ECT, // The Python script name is test. so when I reference the module, I mistakenly use other files. // I guess this is related to searching for files in the Python application module. After I change the name of the script, I can use it all, it took nearly two hours. It was very sweaty!
}
import osimport sysdef hello(a): #print "hello world!" print "execute the func"+str(a) os.mkdir("test") # system("mkdir test")
print "hello world"print "+++++++++++++++++++"
The above is hello. py
Some basic usage of Objective C API