c++调用python模块无法取得返回值
时间:2011-07-18
来源:互联网
在C++里调用python的rec模块
pFunc = PyObject_GetAttrString(mReceiveEmailModule, "rec");
result = PyEval_CallObject(pFunc, pArg);
PyArg_Parse(result,"s", &iresult);
cout << iresult << endl;
我打印的时候发现我需要的值是空的,神马回事?
python代码:
def rec(user,passwd,se,idx):
global html
global text
try:
try:
server=poplib.POP3(se)
except:
print "link to server failed, try again"
rec(user,passwd,se,idx)
try:
server.user(user)
server.pass_(passwd)
except:
print "POP3 server login failed, please check the user name and password"
return "2"
mailCount,size=server.stat()
print mailCount
print size
hdr,message,octet=server.retr(int(idx))
mail=email.message_from_string(string.join(message,'\n'))
subject=email.Header.decode_header(mail['subject'])[0][0]
subcode=email.Header.decode_header(mail['subject'])[0][1]
strr = subject
if subcode == None:
strr = subject
else:
strr = unicode(subject, subcode)
html += "subject:\t" + strr +"\n"
strr = email.utils.parseaddr(mail.get("from"))[1]
html += "from:\t" + strr + "\n"
strr = email.utils.parseaddr(mail.get("to"))[1]
html += "to:\t" + strr + "\n"
showmessage(mail)
server.quit()
print "success!"
except Exception, e:
print str(e)
return "1"
print "*************"
return html
pFunc = PyObject_GetAttrString(mReceiveEmailModule, "rec");
result = PyEval_CallObject(pFunc, pArg);
PyArg_Parse(result,"s", &iresult);
cout << iresult << endl;
我打印的时候发现我需要的值是空的,神马回事?
python代码:
def rec(user,passwd,se,idx):
global html
global text
try:
try:
server=poplib.POP3(se)
except:
print "link to server failed, try again"
rec(user,passwd,se,idx)
try:
server.user(user)
server.pass_(passwd)
except:
print "POP3 server login failed, please check the user name and password"
return "2"
mailCount,size=server.stat()
print mailCount
print size
hdr,message,octet=server.retr(int(idx))
mail=email.message_from_string(string.join(message,'\n'))
subject=email.Header.decode_header(mail['subject'])[0][0]
subcode=email.Header.decode_header(mail['subject'])[0][1]
strr = subject
if subcode == None:
strr = subject
else:
strr = unicode(subject, subcode)
html += "subject:\t" + strr +"\n"
strr = email.utils.parseaddr(mail.get("from"))[1]
html += "from:\t" + strr + "\n"
strr = email.utils.parseaddr(mail.get("to"))[1]
html += "to:\t" + strr + "\n"
showmessage(mail)
server.quit()
print "success!"
except Exception, e:
print str(e)
return "1"
print "*************"
return html
作者: zhyajshhz 发布时间: 2011-07-18
PyArg_Parse(result,"s", &iresult);这句不对吧,改下试试:
iresult = PyString_AsString(result);
iresult = PyString_AsString(result);
作者: angel_su 发布时间: 2011-07-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28