如何将 NSDictionary 转换为 Python 字典?
我有一个完全用 Python 使用 PyObjC 编写的插件,我需要将其核心类转换为 Objective-C。其中之一基本上只是加载一个 Python 模块并执行一个特定的函数,并向其传递关键字参数。在 PyObjC 中,这非常严重。
然而,我很难弄清楚如何使用 Python C API 来做同样的事情。特别是,我不确定如何最好地将 NSDictionary(可能包含整数、字符串、布尔值或以上所有内容)转换为一种格式,然后我可以将其作为关键字参数传递给 Python。
有人知道如何完成这样的事情吗?提前致谢!
编辑:只是为了澄清一下,我正在将以前的 Python 现有类转换为 Objective-C,并且无法弄清楚如何从 Objective-C 中的 NSDictionary 迁移到 Python 字典当我调用剩余的 Python 脚本时可以继续。 Objective-C 类基本上只是一个 Python 加载器,但我不熟悉 Python C API,并且无法弄清楚在哪里寻找对我有帮助的示例或函数。
I have a plugin written entirely in Python using PyObjC whose core classes I need to convert to Objective-C. One of them basically just loads up a Python module and executes a specific function, passing it keyword arguments. In PyObjC, this was extremely.
However, I'm having difficulty figuring out how to do the same thing using the Python C API. In particular, I'm unsure how best to convert an NSDictionary (which might hold integers, strings, booleans, or all of the above) into a format that I can then pass on to Python as keyword arguments.
Anyone have pointers on how to accomplish something like this? Thanks in advance!
Edit: just to clarify, I'm converting my existing class which was formerly Python into Objective-C, and am having trouble figuring out how to move from an NSDictionary in Objective-C to a Python dictionary I can pass on when I invoke the remaining Python scripts. The Objective-C class is basically just a Python loader, but I'm unfamiliar with the Python C API and am having trouble figuring out where to look for examples or functions that will help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,看来我误解了你的问题。好吧,走向另一个方向并没有太大的不同。这应该是(至少是一个开始)您正在寻找的功能(不过我还没有彻底测试过它,所以要小心错误):
您可能还想看看 Python/C API 参考手册(如果您还没有)。
Oh, looks like I misunderstood your question. Well, going the other direction isn't terribly different. This should be (as least a start of) the function you're looking for (I haven't tested it thoroughly though, so beware of the bugs):
You may also want to take a look at the Python/C API Reference manual if you haven't already.