C++调用python

本文以实例code讲解 C++ 调用 python 的方法。


本文在util.h中实现三个函数:

1. init_log: 用google log(glog)初始化log
2. exe_command: 由 C++ 执行 shell code
3. exe_py: C++调用python文件


Code:

Python:

def pr(args):
    for arg in args:
        print arg



C++:
include/util.h:

/*************************************************************************** 
 *-                                                                          
 * Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved                    
 *-                                                                          
 **************************************************************************/ 
-                                                                            
-                                                                            
-                                                                            
/**                                                                          
 * @file util.h                                                              
 * @author zhangruiqing01([email protected])                          
 * @date 2015/10/24 02:17:56                                                 
 * @version $Revision$-                                                      
 * @brief-                                                                   
 *  i                                                                        
 **/                                                                         



#ifndef  __UTIL_H_                                                           
#define  __UTIL_H_                                                           

#include "glog/logging.h"                                                    
#include                                                             
#include                                                             

#define PYTHON_LIB_PATH "~/.jumbo/lib/python2.7"                             
#define PYTHON_BIN_PATH "~/.jumbo/bin/python2.7"                             

// initial log                                                               
void init_log(const char* argv);                                             

// exe shell command 

你可能感兴趣的:(Python,C/C++,shell,python,command,Makefile,C++)