hanqing-yu/hanqing-yu.github.io

Python 调用 C++ | iqhy's Blog

Opened this issue · 9 comments

https://iqhy.github.io/posts/2020/0228155601/

Python 的代码优雅而实用,但是经常会遇到性能问题,这时可以使用 C/C++ 重写几个函数来解决,这样就同时兼顾了开发效率和性能。

I wanna know how to comment

OK, so I comment here and the website has the same words.....

OK, so don't forget that : when you try to build *.pyx file. don't mix tabs and spaces. otherwise, the error will be like complieError: PyRectangle.pyx Mix use tabs and spaces

Also, you can add the second Extension in the "setup.py" , just copy the same format of the first Extension, the comma after the last ')' can be there or not, seems whatever

All my experience trying these two examples.

@pokjnb
Thanks for sharing your experience. Are you unable to leave a comment on my website? Maybe there is a problem with the comment plugin.

@iqhy yeah, can not leave messages. I comment in GitHub website

@iqhy since you know how to use the c++ class in python script, maybe you have experience in debugging them both? like, mix debug in Visual Studio or any other IDE?

@pokjnb Okay, I will try to fix it. My codes is not so complicated, so I just debug in pure c++, and then in python. By the way, there is a tutorial to debug them both in Visual Studio, but I didn't try it.

also, if you want to read the value in the black window, you should add the -i option to the Interpreter Arguments of this project. By the way, print(rect.get_area) can not see the value, change it to print(rect.get_area())

@iqhy I read that article, but it did not work. 😭

@pokjnb I am also not familiar with it. Maybe you can save the inputs in a file in python, and read them in c++ as I do. This simple method works for me.😂