易截截图软件、单文件、免安装、纯绿色、仅160KB

Boost Python 实现C调用python错误解决方法

由于Boost Python跟不上Python版本更新,如下方法调用可能产生TypeError: 'NoneType' object does not support item assignment异常。
Boost Python文档中例子可能产生异常。
Py_Initialize();
object main_module = import("__main__");
object main_dict = main_module.attr("__dict__");
try{
   object result = exec("result = 5 + 5",main_dict);
   int five_squared = extract<int>(main_dict["result"]);
   cout<<"extract value : "<<five_squared<<endl;
   cin>>ij;
}
    catch(error_already_set){
        PyErr_Print();
        cin>>ij;
    }
可以如下方法解决
Py_Initialize();
object main_module = import("__main__");
object main_dict = main_module.attr("__dict__");
try{
    handle<> ignored((PyRun_String(
        "result = 5 ** 2"
        , Py_file_input
        , main_dict.ptr()
        , main_dict.ptr())
    ));
   int five_squared = extract<int>(main_dict["result"]);
   cout<<"extract value : "<<five_squared<<endl;
   cin>>ij;
}
    catch(error_already_set){
        PyErr_Print();
        cin>>ij;
    }
Boost Python中执行表达式函数也可以正常运行。
Py_Initialize();
object main_module = import("__main__");
object main_dict = main_module.attr("__dict__");
try{
   object result = eval("5 + 5",main_dict);
   int five_squared = extract<int>(result);
   cout<<"extract value : "<<five_squared<<endl;
   cin>>ij;
}
    catch(error_already_set){
   


相关文档:

SQLite C/C++接口介绍

这篇文章是使用SQLite C/C++接口的一个概要介绍和入门指南。
由于早期的SQLite只支持5个C/C++接口,因而非常容易学习和使用,但是随着SQLite功能的增强,新的C/C++接口不断的增加进来,到现在有超过150个不同的API接口。这往往使初学者望而却步。幸运的是,大多数SQLite中的C/C++接口是专用的,因而很少被使用到。尽管有这 ......

python PIL 批量处理处理图片

客户给一堆图片要传到后台,图片太大了,上百张图用photoshop改太慢,就想到用python写个简单的批处理。功能简单就是把原图按比例缩小,代码更简单 20多行。
# -*- coding: cp936 -*-
import Image
import glob, os
#图片批处理
def timage():
for files in glob.glob('D:\\1\\*.JPG'):
filepath,filena ......

Python笔记(9)

Python中的文件操作以及输入输出
我们可以分别使用raw_input和print语句来完成这些功能。对于输出,你也可以使用多种多样的str(字符串)类。例如,你能够使用rjust方法来得到一个按一定宽度右对齐的字符串。利用help(str)获得更多详情。
 
 
另一个常用的输入/输出类型是处理文件。创建、读和写文件的能力是 ......

删除C/C++注释

/********************************************************************
*删除C/C++注释
**********************************************************************/
#include <stdio.h>
//注意
//1.对/****/的处理
//2.要保留双引号之间的内容,如char* test = "/*i am not comment */";
//3.对� ......

c/c++文件读写操作总结

在编程的过程中,文件的操作是一个经常用到的问题,在C++Builder中,可以使用多种方法对文件操作,下面我就按以下几个部分对此作详细介绍,就是:
 
1、基于C的文件操作;
2、基于C++的文件操作;
3、基于WINAPI的文件操作;
4、基于BCB库的文件操作;
5、特殊文件的操作。
 
壹、基于C的文件操作
  在A ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号