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);
!
Ïà¹ØÎĵµ£º
ΪÁËʵÏÖÁ½¸öÊý×Ö½øÐн»»»£¬ÎÒÃÇͨ³£¿ÉÒÔÀûÓÃλÔËËãÀ´ÊµÏÖ
C++³ÌÐò swap(int a ,int b){a^=b^=a^=b;}
JAVA³ÌÐò swap(int a, int b){ a^=b;b^=a;a^=b; }»òÕß{ b^=(a^=b) ; a^=b;}
Èç¹ûJAVAÓÃC++µÄʵÏÖ·½Ê½Ôò»áµÃµ½ bµÃµ½ÁËaµÄÖµ£¬µ«ÊÇaÏÖÔÚµÄֵȴ² ......
VB
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = i1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
MSComm1.InBufferCount = 0
& ......
ZoundryDocument
Python skin is known for its color variations and for its elasticity; it is
the warmest leather of the season and ideal for the manufacture of many luxury
goods. Sometimes natural patterns can be hidden when they're done in black, but
the finish here has a bit of a shine to it ......
$ ×Ö·û´®µÄĩβ
^ ×Ö·û´®µÄ¿ªÊ¼
\b ×Ö·ûµÄ±ß½ç
ǰ׺t ×Ö·û´®Öеķ´Ð±Ïߣ¨ËùÓÐ×Ö·û£©²»×ªÒå
? ¿ÉÑ¡µØÆ¥Åä(λÓÚ֮ǰµÄ)µ¥¸ö×Ö·û
() ¸Ä±äÓÅÏȼ¶£¬×÷Ϊһ¸öÕûÌ壬һ¸ö×é
| »òÕß
(A|B) ¾«È·Æ¥ÅäA»òBÖеÄÒ»¸ö
{n,m} Æ¥Å䣨λÓÚ֮ǰµÄ×Ö·û£©nµ½m´Î
VERBOSE ......