PythonǶÈëC++Ïê½â(3)
¼Ìǰƪ¡¶Import Module¡·£¨http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx£©£¬¼ÌÐø·ÖÎöǶÈ벿·Ö»ù´¡ÖªÊ¶¡£Õâ´Î²»¶à˵£¬ÓÐʲôÎÊÌâ¼ÇµÃ¶à²éÓ¢ÎÄ×ÊÁÏ£¬¹úÄÚµÄÕâ·½Ãæ֪ʶÉÙ
»¹ÊÇÀ´¿´´úÂ룬дÍêÎÒ¾Í˯¾õÁË~
#include "python/python.h"
#include <iostream>
using namespace std;
int main(int argc,char** argv)
{
PyObject *pModule, *pClass,*pStuObj,*pFunc;
Py_Initialize();
////////////////
//ÔØÈëÄ£¿éstu.py
pModule = PyImport_ImportModule ("stu");
//´ÓÄ£¿éÖеõ½ÀàStudent
pClass = PyObject_GetAttrString (pModule, "Student");
//Éú³ÉÒ»¸öѧÉú¶ÔÏójack,×¢Òâ3.1°æ±¾±ØÐë¼ÓÉÏСÀ¨ºÅ£º(s)£¬·ñÔò»á³ö´í
//PyObject_CallObjectºÍÁíÍâÒ»¸ö³£ÓõÄPyEval_CallObjectÓ÷¨¼«ÎªÏà½ü£¬Çë¿´¸½Â¼²¿·ÖÏê½â
PyObject * temp=Py_BuildValue("(s)","jack");
pStuObj = PyObject_CallObject(pClass, temp);
//»ñµÃº¯Êý¶ÔÏójackÖеijÉÔ±º¯ÊýprintName£¬
//Õâ¸ögetattrµÄÒâ˼¾ÍÊǵõ½µ±Ç°¶ÔÏóµÄÊôÐÔ£¨²»Òª¾ÖÏÞÓÚC++ÖеÄÊôÐÔŶ£©
pFunc= PyObject_GetAttrString (pStuObj, "printName");
//µ÷Óú¯ÊýprintName
PyEval_CallObject (pFunc, NULL);
////////////////
Py_Finalize();
return 0;
}
/*
¸½Â¼£º
1£ºStudentÀ࣬ÎÒ·¢ÏÖprintºóÃæÏÖÔÚ±ØÐë¼ÓÉÏСÀ¨ºÅÁË£¬·ñÔò»áÓÐÎÊÌâ
class Student:
name=""
def __init__(self,name):
self.name=name
def printName(self):
print (self.name)
2£ºPyObject_CallObjectºÍ PyEval_CallObject²»Í¬Ö®´¦£º
¿ÉÒÔ¿´³ö£¬ºóÕß½ÏΪֱ½Ó£¬¶øÇÒ½ÓÊÜNULL£¬and does explicit type checks
for args and kwds.
PyObject_CallObject(PyObject *o, PyObject *a)
{
! PyObject *r;
! PyObject *args = a;
!
! if (args == NULL) {
! args = PyTuple_New(0);
! if (args == NULL)
! return NULL;
! }
!
! r = PyEval_CallObject(o, args);
!
Ïà¹ØÎĵµ£º
Ш×Ó
¡¡¡¡ È¥Ä꣬ÖÜÐÇÐÇ´ó¸çÔø¾ÔÚVCKBASE/C++ÂÛ̳·¢±í¹ýһƪÎÄÕ“Êý×éÒýÓÃ"ÒÔ±ÜÃâ"Êý×é½µ½×”£¬µ±Ê±ÎÒ²»ÄÜÉîÈëÀí½âÕâÖÖÓ÷¨µÄº¬Ò壻ʱ¸ôÒ»Ä꣬ÎÒµÄ֪ʶÓм¸¾´¸Á¶£¬ÖÕÓÚ¶Ô´ËÎÄÕ½¥ÓÐËùÎò£¬ËùÒÔ°ÑÎáËùÖª×÷Ïë¾ßÌåµÀÀ´£¬¾¹Ò²³ÉÁËһƪÎÄÕ¡£Ï£Íû±¾ÎÄÄܶÔÐÂÊÖÓÐËùÆôµÏ£¬Í¬Ê±Ò²Ï£Íû´ó¼Ò·¢ÏÖ±¾ÎÄÖеÄÊè©֮´¦ºó²»ÁßÁô ......
Õâ¸öÎĵµ¼òµ¥½éÉÜÁËÔõôʹÓÃC++ΪPHP±àдһ¸öÀ©Õ¹Ä£¿é¡£ÎÒÒѾ±»Îʼ°Õâ¸öÎÊÌâÎÞÊý´ÎÁË£¬ËùÒÔÎÒ¾ö¶¨ÎªºóÀ´Õßдһ¸ö¼òµ¥µÄHOWTO¡£ÕâƪÎÄÕÂÖ»»á˵Ã÷һЩҪµãºÍ¹Ø¼üÖ®´¦£¬Èç¹ûÄãÏ£ÍûѧϰC++»òPHP£¬Çë²éÔÄÆäËüµÄÎĵµ¡£
˳±ã£¬ÔÚ±¾ÎÄÖÐÎÒÃÇÒ²»á¿´Ò»ÏÂÔÚPHP5ÖÐÔõô°ÑC++ÀàÓ°Éäµ½PHPÖС£ÎÄÕÂÖеÄÀý×Ó¿ÉÒÔÔÚPHP4ºÍPHP5µÄ»·¾³ÏÂÊ¹Ó ......
1. ʼþÇý¶¯
Ò»¸öʼþ¼°Æä»Øµ÷µÄÀý×ÓÊÇÊó±êÒƶ¯¡£ÎÒÃǼÙÉèÊó±êÖ¸ÕëÍ£ÔÚÄúGUI ³ÌÐòµÄij´¦¡£Èç¹ûÊó±ê±»ÒƵ½Á˳ÌÐòµÄ±ð´¦£¬Ò»¶¨ÊÇÓÐʲô¶«Î÷ÒýÆðÁËÆÁÄ»ÉÏÖ¸ÕëµÄÒƶ¯£¬´Ó¶ø±íÏÖÕâÖÖλÖõÄתÒÆ¡£ÏµÍ³±ØÐë´¦ÀíÕâЩÊó±êÒƶ¯Ê¼þ²ÅÄÜÕ¹ÏÖ£¨²¢ÊµÏÖ£©Êó±êÔÚ´°¿ÚÉϵÄÒƶ¯¡£Ò»µ©ÄúÊÍ·ÅÁËÊó±ê£¬¾Í²»ÔÙ»áÓÐʼþÐèÒª´¦ ......
¶þ½øÖÆÎļþÏÂÔصØÖ·£º
SinaGetBook
Ч¹ûÈçͼ£º
´úÂ룺
#!/usr/bin/env python
#coding=utf-8
#!/usr/bin/env python
#coding=utf-8
import traceback
import sys
import wx
import re
import urllib
import wx.richtext as rt
import wx.lib.buttonpanel as bp
import Casing
import Debug
def trace_back ......
#---------------------תתתתתתתתתתתתתתתתתתתתתתת-------------------------------------------#
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊܺÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨Ìص㣬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óá£
¡¡¡¡ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó ......