锘??xml version="1.0" encoding="utf-8" standalone="yes"?>精品国产日韩久久亚洲,亚洲精品乱码久久久久久自慰 ,久久久久久毛片免费播放http://m.shnenglu.com/zhaoyg/category/17036.html璁板綍鐐規淮錛屾垚灝辨湭鏉?/description>zh-cnThu, 02 Jun 2011 03:30:03 GMTThu, 02 Jun 2011 03:30:03 GMT60C++涓皟鐢╬ython鍑芥暟http://m.shnenglu.com/zhaoyg/archive/2011/06/02/147938.htmlzhaoygzhaoygThu, 02 Jun 2011 03:22:00 GMThttp://m.shnenglu.com/zhaoyg/archive/2011/06/02/147938.htmlhttp://m.shnenglu.com/zhaoyg/comments/147938.htmlhttp://m.shnenglu.com/zhaoyg/archive/2011/06/02/147938.html#Feedback0http://m.shnenglu.com/zhaoyg/comments/commentRss/147938.htmlhttp://m.shnenglu.com/zhaoyg/services/trackbacks/147938.html浠ヤ笅鏄氳繃boost::python瀹炵幇鐨勶紝python鐗堟湰2.7
int main()
{
    Py_Initialize();

    PyObject 
* pModule = NULL;//澹版槑鍙橀噺
    PyObject * pFunc = NULL;// 澹版槑鍙橀噺
    pModule =PyImport_ImportModule("helloworld");//榪欓噷鏄璋冪敤鐨勬枃浠跺悕

    
if (!pModule)
        cout 
<< "err";

    handle
<>* _module; // Module handle.

    _module 
= new handle<>(pModule);

    
// 閫氳繃call_method
    int i = call_method<int>(_module->get() , "Hello" , 4);  

    
// 閫氳繃attr
    main_module.attr("Hello")(2);

    
// main_module.attr("Hello")(2); 灞曞紑濡備笅
    object main_module(*_module);
    
object FunObj = main_module.attr("Hello");  // 鑾峰彇hello鍑芥暟瀵硅薄

    
// 閫氳繃object鐖剁被鐨刼perator()鎿嶄綔絎?/span>
    FunObj(1); 

    
// 閫氳繃call
    i = call<int>(FunObj.ptr(), 3);


    { 
// 閬嶅巻涓閬峱ython鍐呯疆綾誨瀷list瀵硅薄涓殑鍊?/span>
        list  List = call_method<list>(_module->get() , "getList");

        
int n = len(List);

        
for (int i = 0 ; i < n ; i++)
        {
            int val = extract<int> (List[i]);  // 鑾峰彇List[i]浜х敓鐨刼bject瀵硅薄涓殑鍊?/span>錛岄氳繃extract妯℃澘鏉ヨ漿鎹?br />            cout << val << " ";
        }
    }


    
return 0;
}





zhaoyg 2011-06-02 11:22 鍙戣〃璇勮
]]>
閫氳繃Boost::Python瀹炵幇C++瀵硅薄瀵煎叆python鐜http://m.shnenglu.com/zhaoyg/archive/2011/06/01/147885.htmlzhaoygzhaoygWed, 01 Jun 2011 09:34:00 GMThttp://m.shnenglu.com/zhaoyg/archive/2011/06/01/147885.htmlhttp://m.shnenglu.com/zhaoyg/comments/147885.htmlhttp://m.shnenglu.com/zhaoyg/archive/2011/06/01/147885.html#Feedback0http://m.shnenglu.com/zhaoyg/comments/commentRss/147885.htmlhttp://m.shnenglu.com/zhaoyg/services/trackbacks/147885.html
浠ヤ笅鍙槸瀵硅嚜宸辨懜绱㈢粨鏋滅殑鎬葷粨錛屽叾涓毦鍏嶅瓨鍦ㄩ敊璇紝濡傛湁浠諱綍閿欒錛屾湜涓嶆儨鎸囨

綾誨畾涔夛細
class Demo
{
private:
    
int m_val;
    
string m_nam;

public:
    
void setVal(int val)
    {
        m_val 
= val;
    }

    
int getVal()
    {
        
return m_val;
    }

    
void setName(const char *name)
    {
        m_nam 
= name;
    }

    
const char* getName()
    {
        
return m_nam.c_str();
    }
    
void show()
    {
        std::cout 
<<"hello world" <<std::endl;
    }

};

鏂規硶涓錛?/strong>
void fun1()
{
    Py_Initialize();

    PyObject 
*pModule = PyImport_ImportModule("helloworld");

    handle
<>_module(pModule);

    
object main_module(_module);

    
// 瀵煎嚭C++綾誨埌python涓?/span>
    main_module.attr("Demo")  = class_ <Demo>("Demo") // 閫氳繃boost::python涓殑class_灝咰++綾誨寘瑁呮垚object綾誨瀷錛屽洜涓簆ython涓墍鏈夌被鍨嬮兘鏄痮bject
        .def(
"setVal"&Demo::setVal)
        .def(
"setName"&Demo::setName)
        ;


    
// 閫氳繃boost::python鎻愪緵鐨勬ā鏉垮嚱鏁皃tr錛屾潵灝咲emo瀵硅薄浼犲叆python
    Demo a;
    main_module.attr(
"test"= object(ptr(&a));

    std::cout 
<<"涔嬪墠:"<< a.getName() << " " << a.getVal()<<endl;

    call_method
<void>(pModule , "fun2");

    std::cout 
<<"涔嬪悗:"<< a.getName() << " " << a.getVal()<<endl;

    // 閫氳繃python鍑芥暟榪斿洖C++瀵硅薄
    Demo tmp = call_method<Demo>(pModule , "ReturnCppClass");
    std::cout << tmp.getName() << " " << tmp.getVal() <<endl;
}

helloworld.py鑴氭湰鍐呭錛?br />
def fun2():
    tmp 
= test;
    tmp.setVal(
12345);
    tmp.setName(
"2011-5-19");

def ReturnCppClass():
    tmp = Demo();
    tmp.setName('123456789')
    tmp.setVal(99);
    return tmp;

1.璇彞main_module.attr("test"= object(ptr(&a)); 涓殑"test"鏄痑瀵硅薄鍦ㄨ剼鏈腑鐨勫埆鍚嶏紝浜庢槸鑴氭湰涓彲浠ョ洿鎺ラ氳繃test鍚嶅瓧鎿嶄綔C++瀵硅薄銆?br />2.Demo tmp = call_method<Demo>(pModule , "ReturnCppClass");鏉ュ疄鐜板湪python涓垱寤篊++瀵硅薄錛屽茍涓旇繑鍥炲埌C++涓?br />
鏂規硶浜岋細
閫氳繃鏅鴻兘鎸囬拡瀹炵幇C++瀵硅薄鐨勫鍏?strong>
typedef boost::shared_ptr < Demo > Demo_ptr;
void fun2()
{
    Py_Initialize();

    Demo_ptr spD1(
new Demo);

    spD1
->setName("NULL");
    spD1
->setVal(0);

    
try
    {
        PyObject 
*pModule = PyImport_ImportModule("helloworld");

        register_ptr_to_python 
<Demo_ptr>();  // 娉ㄥ唽鍙兘鎸囬拡

        handle
<>* _module;

        _module 
= new handle<>(pModule);
        
object main_module(*_module);

        
object dictionary = main_module.attr("__dict__");
        dictionary[
"Demo"= class_ <Demo>("Demo")
            .def(
"setVal"&Demo::setVal)
            .def(
"setName"&Demo::setName)
            ;

        main_module.attr(
"DemoObj"= spD1; // 娣誨姞鏅鴻兘鎸囬拡鍒拌剼鏈紝騫墮噸鍛藉悕

        call_method
<void>(pModule , "SetObj"); // 鍦ㄨ剼鏈腑閫氳繃鎿嶇旱鏅鴻兘鎸囬拡鏉ユ帶鍒跺璞?/span>

        std::cout 
<< a.getName() << " " << a.getVal()<<endl;
    }
    
catch (error_already_set) 
    {
        PyErr_Print();
    }

    std::cout 
<< "spD1->getName(): " << spD1->getName() <<std::endl;
    std::cout 
<< "spD1->getVal(): " << spD1->getVal() <<std::endl;
}

鑴氭湰鍐呭錛?br />
def SetObj():
    DemoObj.setVal(
100);
    DemoObj.setName(
'hello');

1.register_ptr_to_python <Demo_ptr>(); 娌℃湁榪欏彞榪愯鏃朵細寰楀埌閿欒銆傚叧浜巖egister_ptr_to_python錛宐oost涓殑瑙i噴鏄細
“a function template which registers a conversion for smart pointers to Python”

2.
dictionary["Demo"= class_ <Demo>("Demo")
            .def(
"setVal"&Demo::setVal)
            .def(
"setName"&Demo::setName)
            ;
涓庢柟娉曚竴涓殑錛?br />
main_module.attr("Demo")  = class_ <Demo>("Demo")
        .def(
"setVal"&Demo::setVal)
        .def(
"setName"&Demo::setName)
        ;

鏁堟灉涓鏍楓?br />
-----------------------------------------------------------------------------------
浠ヤ笂灝辨槸鍏充簬濡備綍灝咰++瀵硅薄浼犲叆python鐨勪竴鐐逛範寰楋紝濡傛湁浠諱綍閿欒錛屾湜涓嶆儨鎸囨
-----------------------------------------------------------------------------------

P.S.: cppblog鎻愪緵鐨勭紪杈戝櫒涓嶅ソ鐢?img src ="http://m.shnenglu.com/zhaoyg/aggbug/147885.html" width = "1" height = "1" />

zhaoyg 2011-06-01 17:34 鍙戣〃璇勮
]]>
鍏充簬C++宓屽叆python鑴氭湰鍚庣殑紼嬪簭鍙戝竷闂http://m.shnenglu.com/zhaoyg/archive/2011/04/25/142659.htmlzhaoygzhaoygMon, 25 Apr 2011 01:57:00 GMThttp://m.shnenglu.com/zhaoyg/archive/2011/04/25/142659.htmlhttp://m.shnenglu.com/zhaoyg/comments/142659.htmlhttp://m.shnenglu.com/zhaoyg/archive/2011/04/25/142659.html#Feedback0http://m.shnenglu.com/zhaoyg/comments/commentRss/142659.htmlhttp://m.shnenglu.com/zhaoyg/services/trackbacks/142659.html
浜庢槸閫氳繃鍏抽敭瀛?#8220;C++宓屽叆python 鍙戝竷”錛屾壘鍒頒簡涓涓敤py2exe鏉ヨВ鍐抽棶棰橈紝浣嗘垜璇曚簡鍗婂ぉ閮芥病鎴愬姛錛堜篃璁告槸鎴戣嚜宸辨病寮勫鐨勫師鍥狅紝鍥犱負浜哄閮芥垚鍔熶簡錛夈?br />鍐嶅悗鏉ユ垜鎶婂叧閿瓧鏀逛負浜?#8220;python C++ distribute embed”錛堝嵆鑻辨枃鍏抽敭瀛楋級錛岃繖涓嬫嫧浜戣澶╀簡錛屽洜涓哄湪Google鐨勭涓欏靛氨鏈変竴涓鍥藉笘瀛愬叾鏍囬姝e拰鎴戞剰錛堟灉鐒惰嫳璇粰鍔涳級銆?br />
鐪嬩簡閭d釜璐村瓙鍙戠幇錛屼箣鎵浠ヤ笉鑳藉湪娌℃湁瀹夎python鐨勬満瀛愪笂榪愯鏄洜涓猴細


In addition to pythonxy.dll, you also need the entire Python library, i.e. the contents of the lib folder, plus the extension modules, i.e. the contents of the DLLs folder. Without the standard library, Python won't even start, since it tries to find os.py (in 3.x; string.py in 2.x). On startup, it imports a number of modules, in particular site.py.


鍘熸枃錛?a >http://stackoverflow.com/questions/1387906/c-with-python-embedding-crash-if-python-not-installed


zhaoyg 2011-04-25 09:57 鍙戣〃璇勮
]]>
久久婷婷五月综合色高清| 久久成人国产精品二三区| 国产综合免费精品久久久| 亚洲Av无码国产情品久久| 久久只有这里有精品4| 99精品国产在热久久无毒不卡| 国产成人久久激情91| 性欧美大战久久久久久久| 99久久精品免费看国产一区二区三区| 日本欧美久久久久免费播放网| 91久久婷婷国产综合精品青草| 理论片午午伦夜理片久久| 久久AV高清无码| 热久久最新网站获取| 99久久精品毛片免费播放| 亚洲欧美一级久久精品| 久久国产精品成人免费| 国产成年无码久久久免费| 久久91这里精品国产2020| 韩国免费A级毛片久久| 伊人久久大香线蕉综合网站| 狠狠色综合久久久久尤物| 久久国产精品成人片免费| 久久久久久久久久久精品尤物| 嫩草影院久久国产精品| 77777亚洲午夜久久多喷| 99精品久久精品一区二区| 伊人色综合久久天天网| 99久久www免费人成精品| 久久最新精品国产| 国产成人综合久久综合| 欧美久久综合性欧美| 1000部精品久久久久久久久| 91精品国产9l久久久久| 精品久久久久久无码专区| 精品久久久久久久无码| 亚洲AV无码1区2区久久| …久久精品99久久香蕉国产 | 99久久中文字幕| 亚洲国产精品高清久久久| 久久精品免费一区二区|