[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
Here is an example of the problem this module addresses (but you have to pretend that some of these calls are made by linked-in ...
Example 20-11. PP4E\Integrate\Extend\Cenviron\envattr.py import os from cenviron import getenv, putenv # get C module's methods ...
And you’re done. Well, almost; you still need to run this file through SWIG and compile its output. As before, simply add a SWIG ...
If you look closely, you may notice that I didn’t call putenv this time. It turns out there’s good cause: the C library’s putenv ...
As we did earlier, to use SWIG in this domain, write and debug your class as though it would be used only from C++. Then, simply ...
Number::Number(int start) { data = start; // python print goes to stdout printf("Number: %d\n", data); // or: cout << "Num ...
cout << "data+1: " << val + 1 << endl; num->display(); cout << num << endl; // print raw instan ...
This interface file simply directs SWIG to read the C++ class’s type signature infor- mation from the %-included number.h header ...
number_wrap.cxx: number.i $(SWIG) -c++ -python number.i number.py: number.i $(SWIG) -c++ -python number.i wrapped C++ class code ...
num.display() # num saves the C++ 'this' pointer num.sub(2) num.display() res = num.square() # converted C++ int return value pr ...
Number_display(num) # use accessor functions in the C module Number_sub(num, 2) Number_display(num) print(Number_square(num)) Nu ...
print(num.square()) num.data = 99 print(num.data) num.display() num.mul(2) # mul() is implemented in Python num.display() print( ...
>>> x, y (<number.Number; proxy of <Swig Object of type 'Number *' at 0x7ff4bcf8> >, <number.Number; pro ...
details on these and others. Like SWIG, all of the following began life as third-party tools installed separately, though Python ...
tools, this makes the system useful for wrapping existing libraries, as well as developing new extensions from scratch. Writing ...
C-based implementation of Python) code, without requiring alternative byte code compilers. Moreover, the f2py and PyFort systems ...
languages to run Python program code. In this mode, Python acts as an embedded control language (what some call a “macro” langua ...
C API call Python equivalent PyObject_GetAttrString getattr(obj, attr) PyObject_SetAttrString setattr(obj, attr, val) PyObject_C ...
The Python binary library is usually what is physically embedded and linked in the C program. The actual Python code run from C ...
Code files can communicate with most of the same techniques as code strings; when run as separate programs, files can also empl ...
«
73
74
75
76
77
78
79
80
81
82
»
Free download pdf