I find the generated Python wrapper for a C++ function by swig has the following lines:
def my_func(arg):
return _cpp_mod.my_cpp_func(arg)
my_func = _cpp_mod.my_cpp_func
The source code in the .i file is as follows:
%module cpp_mod
... ...
%inline %{
MyObj& my_cpp_func(arg) {
return *new MyObj(arg);
}
%}
All functions of the generated code seem OK.
What I want to know is the purpose of the third line for the
generated python code. Thanks in advance.
It just the way SWIG has decided to wrap functions. The first part
def my_func(arg):
return _cpp_mod.my_cpp_func(arg)
reveals the number of input arguments and if commments are generated, they will be inserted here.
The second part
my_func = _cpp_mod.my_cpp_func
is redefining the function to the generated library function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.