Python 3 Êä³öÖض¨ÏòʹÓÃC/C++
Python 3 Êä³öÖض¨ÏòʹÓÃC/C++
By:gddsky
Ä¿±ê
Ï£Íû½«Python 3µÄÊä³öÖض¨Ïòµ½×Ô¶¨ÒåµÄÊä³öÄ¿±ê¡£
ºËÐÄ
PythonʹÓÃsys.stdout¡¢sys.stderr×öÊä³öÄ¿±ê£¬Ö»ÒªÎÒÃÇÌæ»»ÕâÁ½¸öÖµ¾Í¿ÉÒÔÖض¨Ïòµ½ÎÒÃÇ×Ô¶¨ÒåÄ¿±ê¡£Ìæ»»µÄÖµµÄ¹æÔòÔÚPythonµÄÎĵµÖÐsys (module)µÄsys.stdoutÉÏÃæ˵Ã÷Ö»ÒªÌí¼ÓÒ»¸öwriteº¯Êý¾Í¿ÉÒÔÁË¡£ÏñÕâÑù£º
write(self, str)
ÎÒÃÇÖ»ÒªÔÚÕâ¸öº¯ÊýÀïÃæµ÷ÓÃÎÒÃÇ×Ô¼ºµÄÊä³öº¯Êý¾Í¿ÉÒÔʵÏÖ¸ÃÄ¿±êÁË¡£
·½°¸
ÔÚC++ÖÐдһ¸öPythonÄ£¿é£¬²¢µ¼Èë
ÔÚC++ÖÐÀûÓÃPyRun_SimpleString½¨Á¢Ò»¸öPyObjectÈ¥Ìæ»»ÔʼµÄsys.stdout¡¢sys.stderr
¸ã¶¨£¡£¡£¡
´úÂë
Ä£¿é¶¨Ò岿·Ö´úÂ루ÓÃpython demoϵÄÀý×Ó¸ÄдµÄ£©
static PyObject *console_write(PyObject *self, PyObject* args)
{
if (s_pyConsoleNotify != NULL)
{
const char* pMsgString=0;
if (!PyArg_ParseTuple( args, "s", &pMsgString ))
{
return NULL;
}
// ÎÒÃÇ×Ô¼ºµÄÊä³öº¯Êý
myprint(pMsgString);
}
Py_INCREF( Py_None );
return Py_None;
}
static PyMethodDef console_methods[] = {
{"test", console_test, METH_NOARGS, "Return the meaning of everything."},
{"write", console_write, METH_VARARGS, NULL},
{NULL, NULL} /* sentinel */
};
static struct PyModuleDef consolemodule = {
{}, /* m_base */
"console_capi", /* m_name */
0, /* m_doc */
0, /* m_size */
console_methods,
Ïà¹ØÎĵµ£º
mysqlÊÇÒ»¸öÓÅÐãµÄ¿ªÔ´Êý¾Ý¿â£¬ËüÏÖÔÚµÄÓ¦Ó÷dz£µÄ¹ã·º£¬Òò´ËºÜÓбØÒª¼òµ¥µÄ½éÉÜÒ»ÏÂÓÃpython²Ù×÷mysqlÊý¾Ý¿âµÄ·½·¨¡£python²Ù×÷Êý¾Ý¿âÐèÒª°²×°Ò»¸öµÚÈý·½µÄÄ£¿é£¬ÔÚhttp://mysql-python.sourceforge.net/
ÓÐÏÂÔغÍÎĵµ¡£
ÓÉÓÚpythonµÄÊý¾Ý¿âÄ£¿éÓÐרÃŵÄÊý¾Ý¿âÄ£¿éµÄ¹æ·¶£¬ËùÒÔ£¬Æäʵ²»¹ÜʹÓÃÄÄÖÖÊý¾ ......
´úÂëÈçÏ£º
#!/usr/bin/env python
# -*-coding:UTF-8-*-#
from common import *
import Image, ImageFilter, math, sys, os, random
def modifyImageObj(img, matrix) :
width, height = img.size
for h in range(0, height) :&n ......
½ñÌìͻȻÓÐÒ»¸öÏë·¨£¬¾ÍÊÇÏë×Ô¼ºÐ´Ò»¸ö·Òë½Å±¾¡£¿ÉϧGoogleÌṩµÄAPIÊǹ©ÍøÂçÓ¦Óõġ£¸ÕºÃÔÚ¡¶dive into python¡·ÀïÃæÕâ±¾ÊéÀïÃæ¿´µ½ÈçºÎ´ÓHTMLÎĵµÖÐÌáÈ¡³öÀ´×Ô¼ºÏëÒªµÄÄÚÈÝ£¬ÄÇÕâÑùµÄ»°£¬¿É²»¿ÉÒÔÄ£Äâä¯ÀÀÆ÷À´·¢ËÍÏë·ÒëµÄ¾ä×Ó£¬È»ºóÔÙ½ÓÊÕ·µ»Ø½á¹ûºóµÄHTMLÔ´Â룬×îºó´ÓÖÐÌáÈ¡³ö·ÒëµÄ½á¹ûÄØ£¿¡¡¡¡ÆäʵÊÇÐеģ¬ÒòΪÀûÓ ......
ΪÁË´Ó×Ö·û´®ÖÐÌáȡʱ¼ä£¬²¢½øÐбȽϣ¬Òò´ËÓÐÁËÕâ¸öÎÊÌ⣬ÈçºÎ½«×Ö·û´®×ª»»³ÉdatetimeÀàÐÍ
1.×Ö·û´®ÓëtimeÀàÐ͵Äת»»
>>> import time
>>> timestr = "time2009-12-14"
>>> t = time.strptime(timest ......