开发者

Any good references for python and C code mixing?

开发者 https://www.devze.com 2023-01-20 05:28 出处:网络
I\'ve been looking at docs but I can\'t seem to understand very clearly, them do you guys know of anything that would be good at tea开发者_如何学编程ching it.

I've been looking at docs but I can't seem to understand very clearly, them do you guys know of anything that would be good at tea开发者_如何学编程ching it.

Say I had a program,

int main() {
   return 3;
}

How do I call cprogram.exe and get the return value (not neccesarily an int, structs too). I don't have a specific project that I'm working on, just trying to learn. So on top of answering this question, some references (books or otherwise) to where I could learn continuation of this, because I know its more complicated than this; would be nice; thanks in advance.

lol sentence structure.


The simplest way of doing this would be to create a dll or so (depending on your platform) then use the ctypes module to call into it. The exact method for creating the dll depends on your compiler. For ctypes see http://python.net/crew/theller/ctypes/tutorial.html


Wesley Chun has a nice chapter showing how to do it in his "Core Python Programming" book.


The Python docs themselves may be a good place to start:

http://docs.python.org/release/2.5.2/ext/intro.html

0

精彩评论

暂无评论...
验证码 换一张
取 消