c++于python混合系统的一个难题
这是一个普通的混合使用方式, 但这种方式不能达到脚本真正的灵活性, c++每个属性必须绑定一个唯一的set和get接口提供给python内部访问这个属性
C/C++ code:
class sample
{
public:
int m_obj;
int GetValue(){
return m_obj;
}
void SetValue(int v){
m_obj= v;
}
};
class_<sample>("sample")
.add_property("m_obj", &sample::GetValue, &sample::SetValue )
我看过一个公司做的一个系统使用自己开发的python插件模块实现了非常灵活的c++与python交互
这个系统有一个配置文件, 其中定义着一些属性和接口, 在系统启动时会去分析这些配置然后把它们
建立在python中, 用户在python中对这些配置定义的属性赋值都会被c++所截获
下面是按照我的设想去做, 当然下面代码不能运行 因为不支持这样的方式。
用户在配置文件定义了3个属性
int obj1, float obj2, string obj3
把它们绑定到一个通用的接口上
.add_property("obj1", &bind(&sample::GetValue, 1), &bind(&sample::SetValue, 1 ) )
.add_property("obj2", &bind(&sample::GetValue, 2), &bind(&sample::SetValue, 2 ) )
.add_property("obj3", &bind(&sample::GetValue, 3), &bind(&sample::SetValue, 3 ) )
class sample
{
public:
Py
相关问答:
最近突然想自己来实现一个五子棋程序,但不知道怎么开始,自己也没学画图形函数,能在控制台下直接写吗>>>?????
控制台?比图形界面更麻烦。
http://search.download.csdn.net/search/%E4%BA%94%E5%AD%90% ......
已知Python 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试
在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......
请问下,我的是python2.5安装了PIL模块,然后编写程序打开本机上的一个图片时,为什么老出现错误呢,老是找不到图片,错误提示如下:File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1888, in o ......
我每次上传的文件读到的数据都不正确。2M 的图片读得10多K 。。哪位大侠可以帮帮我啊。
#!D:\ProgrammerTools\python26\python.exe
#encoding=utf-8
import cgitb
import os
cgitb.enable()
import cgi,urllib ......
#include"stdio.h"
#include"stdlib.h"
void ContrTwo(char i)
{
char str1[8];
itoa(i,str1,2);
printf("%s",str1);
}
unsigned char leftRot(char str,int i);
unsign ......