Python is an object-oriented, interpreted computer programming language invented by Guido van Rossum in 1989. The first public release was released in 1991. Python is purely free software. The source code and interpreter CPython follow the GPL (GNU General Public License) agreement. Python syntax is concise and clear, and one of its features is the mandatory use of white space as statement indentation. Python has rich and powerful libraries. It is often nicknamed the glue language, which can easily connect various modules made in other languages (especially C/C++) together. "Black Horse Cloud Classroom 8-Day In-depth Understanding of Python Video Tutorial" will give you an in-depth understanding of the Python language.
Video playback address: http://www.php.cn/course/556.html
The difficulty of this video It lies in the call to C/C++:
1. Python calls the C dynamic link library
(1) C language file: pycall.c
int foo(int a , int b)
{
printf("you input %d and %d\n", a, b);
return a+b;
}
import ctypes
ll = ctypes.cdll.LoadLibrary
lib = ll("./libpycall.so")
lib.foo(1, 3)
print '***finish***'
(1) C++ class file: pycallclass.cpp
using namespace std;
class TestLib
{
public:
void display();
void display(int a);
};
void TestLib::display() {
cout}
void TestLib::display(int a) {
cout}
extern "C" {
TestLib obj;
void display() {
obj.display();
void display_int() {
obj.display(2 );
} }
}
(2) g++ compiles and generates the dynamic library libpycall.so: g++ -o libpycallclass.so -shared -fPIC pycallclass.cpp.
(3) Python calls the file of the dynamic library: pycallclass.py
import ctypes
lib = so("./ libpycallclass.so")
print 'display()' lib.display()
print 'display(100)' lib.display_int(100)
The teacher's lectures are relaxed and humorous, and the students Learn without stress. From the simple to the deep, from the deep to the simple, relaxed and cheerful is the overall image of this teacher.
The above is the detailed content of Black Horse Cloud Classroom 8 days of in-depth understanding of Python video materials. For more information, please follow other related articles on the PHP Chinese website!