命令行模式(含参数)
1、sys.argv获取
①cpp_python.cpp:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
cout << "--------Testing---------" << endl;
system("python D:/fastrcnn/src_detect/test.py arg1 arg2");
system("pause");
return 0;
}
②test.py:
# coding:utf-8
# it's an example for receieving an arg
import sys
def sayhello(name='xiaoming'):
print('hello ' + str(name))
args = sys.argv
print('the number of args:', len(args))
print('args:', str(args))
name = args[1]
sayhello(name)
2、getopt 模块来获取命令行参数
参考:http://www.runoob.com/python/python-command-line-arguments.html