Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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, 


Ïà¹ØÎĵµ£º

C/C++ÖÐö¾ÙÀàÐÍ(enum)

Èç¹ûÒ»¸ö±äÁ¿ÄãÐèÒª¼¸ÖÖ¿ÉÄÜ´æÔÚµÄÖµ£¬ÄÇô¾Í¿ÉÒÔ±»¶¨Òå³ÉΪö¾ÙÀàÐÍ¡£Ö®ËùÒÔ½Ðö¾Ù¾ÍÊÇ˵½«±äÁ¿»òÕ߽жÔÏó¿ÉÄÜ´æÔÚµÄÇé¿öÒ²¿ÉÒÔ˵ÊÇ¿ÉÄܵÄÖµÒ»Ò»Àý¾Ù³öÀ´¡£
¡¡¡¡¾Ù¸öÀý×ÓÀ´ËµÃ÷Ò»°É£¬ÎªÁËÈôó¼Ò¸üÃ÷°×Ò»µã£¬±ÈÈçÒ»¸öǦ±ÊºÐÖÐÓÐÒ»Ö§±Ê£¬µ«ÔÚûÓдò¿ªÖ®Ç°Äã²¢²»ÖªµÀËüÊÇʲô±Ê£¬¿ÉÄÜÊÇǦ±ÊÒ²¿ÉÄÜÊǸֱʣ¬ÕâÀïÓÐÁ½ÖÖ¿ÉÄÜ£¬Ä ......

Ì쳯Ҫ½«python¹ÙÍøÏÂÔØÒ³Ãæ·âµ½ºÎʱ£¿

¿É¶ñ¡¢¿É±¯¡¢¿É³Ü¡¢¿ÉÁ¯¡¢¿É̾¡¢¿ÉЦ£¡£¡£¡
2009Äê10ÔÂ15ÈÕ£¬Ò»¸öÁî¹ã´ópython±à³Ì¹¤×÷°®ºÃÕß¿ÞЦ²»µÃµÄÊ·¢ÉúÁË——pythonµÄ¹Ù·½ÍøÕ¾£¨http://www.python.org£©±»Î°´óµÄÌ쳯¸ø·âÁË£¡
µ±Ê±£¬ÓÐÈË˵ÊÇÒòΪÓÐÒ»¸öHÍøÕ¾ºÍpythonµÄ¹ÙÍøºÜÏñ£¬·â´íÁË¡£ÓÚÊÇ£¬ÎÒÊÔ×Å´ò¿ªÁËÄǸö“ÏàËƵÄÍøÕ¾http://www.python.com ......

python ÖÐʹÓÃparamiko¼òµ¥Á¬½Ó

ÔÚparamikoÖÐʹÓÃÓû§ÃûºÍÃÜÂëͨ¹ýsftp´«ÊäÎļþ£¬²»Ê¹ÓÃkeyÎļþ¡£
import getpass
import select
import socket
import traceback
import paramiko
def putfile():
#import interactive
# setup logging
paramiko.util.log_to_file('demo.log')
username = username
hostname = hostname
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ