【发布时间】:2015-12-15 03:50:56
【问题描述】:
python 2.7.10(./Watcher/epMain.py):
import subprocess
import hashlib
import os
import sys
import zipfile
import httplib
#import urllib
#import urllib2
def letsbegin():
subprocess.call('a.exe')
httpClient = httplib.HTTPConnection('www.google.com', 80, timeout=30)
httpClient.request('GET', '/updata/Client_V.html')
response = httpClient.getresponse()
targetV = response.read()
letsbegin()
c++:
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./Watcher')");
PyObject *pyMain = PyImport_ImportModule("epMain")
pyMain 始终是NULL,但是在我将 python 代码更改为:
import subprocess
import hashlib
import os
import sys
import zipfile
#import httplib
#import urllib
#import urllib2
def letsbegin():
subprocess.call('a.exe')
httpClient = httplib.HTTPConnection('www.google.com', 80, timeout=30)
httpClient.request('GET', '/updata/Client_V.html')
response = httpClient.getresponse()
targetV = response.read()
letsbegin()
然后可以在我的 c++ 代码中加载这个模块 但是我很想在这个项目中使用httplib,如何?我不能使用:
PyImport_ImportModule("httplib")
因为 python 代码可能会经常更新。 此外,当我使用
d:\pros\go\Watcher>python epMain.py
有效!urllib和urllib2也有这样的问题。
【问题讨论】:
标签: python c++ python-2.7