从 GDataEntry 中提取 ID 字符串

发布于 2024-12-20 22:11:46 字数 352 浏览 2 评论 0原文

我正在 python 中使用 Google 的 gdata API。更具体地说,我正在使用 YouTube API,但我不认为它与这个问题相关。

我现在有一个对象,它是 GDataEntry 的子类,我正在尝试获取它的 id。

print entry.id

这会失败,因为它无法将 Id 对象转换为字符串。所以我尝试:

print str(entry.id)

将其序列化为 XML 字符串。我真正想要的是ID的文本内容。我一直在查看文档,但到目前为止我还找不到它。我相信这确实很容易做到,但我找不到正确的方法来获取 Id 对象的文本内容。

I am playing around with Google's gdata API in python. More specificalyl, I am using the YouTube API, but I do not believe it will be relevant to this question.

I now have an object which is a subclass of GDataEntry and I am trying to get its id.

print entry.id

this fails as it cannot convert and Id object to a string. So I try:

print str(entry.id)

which serializes it to an XML string. What I really want is the textual content of the ID. I have been looking through the docs, and I was unable to find it so far. I am convinced this is really easy to do, but I cannot find the right method to get the text content of the Id object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-12-27 22:11:47

我很确定,entry.id 的类型为 atom.Id,它提供了 ToString 方法和 text< /code> 访问器。请参阅此处的文档

所以你想写:

print entry.id.text

I'm pretty sure, that entry.id is of the type atom.Id which provides a ToString method and a text accessor. See the documentation here.

So you'd like to write:

print entry.id.text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文