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Ö»Ö§³Ö5¸öC/C++½Ó¿Ú£¬Òò¶ø·Ç³£ÈÝÒ×ѧϰºÍʹÓ㬵«ÊÇËæ×ÅSQLite¹¦ÄܵÄÔöÇ¿£¬ÐµÄC/C++½Ó¿Ú²»¶ÏµÄÔö¼Ó½øÀ´£¬µ½ÏÖÔÚÓг¬¹ý150¸ö²»Í¬µÄAPI½Ó¿Ú¡£ÕâÍùÍùʹ³õѧÕßÍû¶øÈ´²½¡£ÐÒÔ˵ÄÊÇ£¬´ó¶àÊýSQLiteÖеÄC/C++½Ó¿ÚÊÇרÓõģ¬Òò¶øºÜÉÙ±»Ê¹Óõ½¡£¾¡¹ÜÓÐÕâ ......
PythonÖеÄÒì³£
µ±ÄãµÄ³ÌÐòÖгöÏÖijЩÒì³£µÄ×´¿öµÄʱºò£¬Òì³£¾Í·¢ÉúÁË¡£
Ò».´¦ÀíÒì³£
ÎÒÃÇ¿ÉÒÔʹÓÃtry..exceptÓï¾äÀ´´¦ÀíÒì³£¡£ÎÒÃÇ°Ñͨ³£µÄÓï¾ä·ÅÔÚtry-¿éÖУ¬¶ø°ÑÎÒÃǵĴíÎó´¦ÀíÓï¾ä·ÅÔÚexcept-¿éÖС£
ÀýÈç:
#!/usr/bin/python
# Filename: try_except.py
import sys
try:
s = raw_input('E ......
/********************************************************************
*ɾ³ýC/C++×¢ÊÍ
**********************************************************************/
#include <stdio.h>
//×¢Òâ
//1.¶Ô/****/µÄ´¦Àí
//2.Òª±£ÁôË«ÒýºÅÖ®¼äµÄÄÚÈÝ£¬Èçchar* test = "/*i am not comment */";
//3.¶ÔÓ ......
C/SÊÇClient/ServerµÄËõд¡£·þÎñÆ÷ͨ³£²ÉÓøßÐÔÄܵÄPC¡¢¹¤×÷Õ¾»òСÐÍ»ú£¬²¢²ÉÓôóÐÍÊý¾Ý¿âϵͳ£¬ÈçOracle¡¢Sybase¡¢Informix»ò SQL Server¡£¿Í»§¶ËÐèÒª°²×°×¨ÓõĿͻ§¶ËÈí¼þ¡£
B/S ÊÇBrower/ServerµÄËõд£¬¿Í»§»úÉÏÖ»Òª°²×°Ò»¸öä¯ÀÀÆ÷£¨Browser£©£¬ÈçNetscape Navigator»òInternet Explorer£¬·þÎñÆ÷°²×°Oracle¡¢Sybase¡¢In ......
ÕâÀïÌṩµÄÖ»ÊÇÒ»¸öÖ§³Ö¹ÜµÀµÄÃüÁîÖ´ÐнӿÚ, ÖÁÓÚ»ñÈ¡ÃüÁî, À©Õ¹×Ô¼ºµÄÃüÁî, ¾Í²»ÔÙ׸Êö.
¶ÔÓÚϵͳµÄÃüÁî, ¿ÉÒÔÖ±½Óµ÷ÓÃÕâ¸ö½Ó¿Ú·½·¨, ¶à¸öÃüÁîÖ§³Ö¹ÜµÀ²Ù×÷. ·¢Éú´íÎóʱ, Òý·¢OSError.
1. Åжϴ«ÈëÃüÁîÊÇ·ñÊÇ×Ö·û´®ÀàÐÍ
2. ´«ÈëµÄÿ¸öÃüÁî.
3. ±éÀúËùÓÐÃüÁî.
4. »ñȡÿ¸öÃüÁîµÄÃüÁî¼°²ÎÊý
5. ¶¯Ì¬Ö´ÐÐPopen, ......