在python 3中替换PyString_FromString方法 [英] Replacing PyString_FromString method in python 3

查看:209
本文介绍了在python 3中替换PyString_FromString方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR; PyString_FromString 在Python3.5中不起作用,因此我需要一个替代方法.

TLDR; PyString_FromString doesn't work in Python3.5 so I need an alternative.

我正在从该python文档中获取一个在C ++项目中包含python 3的示例: https://docs.python.org/3/extending/embedding.html

I am following an example for including python 3 within a C++ project from this python documentation: https://docs.python.org/3/extending/embedding.html

一切正常,但现在我想更改以下内容:

Everything is working fine but now I want to change the line that reads:

pValue = PyLong_FromLong(atoi(argv [i + 3]));

到以下内容(我也不再使用i,那是从循环开始的):

to the following (I also no longer use i, that was from a loop):

pValue = PyString_FromString(字符串而不是数字");

似乎 PyString_FromString 函数不再是Python3.5的选项,并且在用g ++编译代码时出现以下错误:

It seems the PyString_FromString function is no longer an option Python3.5 and I get the following error when I compile the code with g++:

main.cpp:559:60: error: ‘PyString_FromString’ was not declared in this scope
         pValue = PyString_FromString("A string instead of a number");`

关于我如何解决这个问题的任何想法?无论我要寻找什么,我似乎都找不到一个不会引发错误的解决方案.我需要将一个字符串传递给我的Python文件,并且已经有一个字符串开头.

Any idea on how I get around this? No matter what I look for I can't seem to find a solution that doesn't throw an error. I need to pass a string to my Python file and I have a string to start with already.

推荐答案

这篇关于在python 3中替换PyString_FromString方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆