gpt4 book ai didi

android - pymtp 在 python 3 上工作时出错

转载 作者:行者123 更新时间:2023-11-30 01:57:37 25 4
gpt4 key购买 nike

我想从 python 访问 android 设备以下载一些照片。libmtp 从 CLI 运行。比pymtp .它已经存在了一段时间,但它是为 python 2 设计的,我正在使用 python 3。同时修复了几个小问题,但我被函数 get_filelisting 的错误卡住了特别是这一部分:

ret = []
next = files
while next:
ret.append(next.contents)
if (next(next.contents) is None):
break
next = next(next.contents)

错误与“下一个”有关。

那部分对我来说看起来很奇怪,我用 python 编码已经有一段时间了,但我是 ctypes 的新手。尝试了很多变体,他们都失败了。 “next”可能会与 python 内置函数混淆,因此我将其重命名为 nextpointer 并得出以下代码:

ret = []
nextpointer = files
while nextpointer:
ret.append(nextpointer.contents)
nextpointer = nextpointer.contents.next

它似乎可以工作,但它是偶然工作的吗?它有什么设计缺陷吗?任何有 python ctypes 经验的人都可以确认这是一个解决方案吗?欢迎提出任何建议。

最佳答案

来自python2.7文档

next(iterator[, default])

Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.

来自 python3 文档

next(iterator[, default])

Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.

请注意,next() 方法 已从 python3 中删除,但函数 仍然存在。

关于 next 函数和 .next()/__next__() 方法,我只能说这些了。<​​/p>

我下载了 pymtp 模块,get_filelisting() 与您在移植代码中发布的略有不同,这里是:

ret = []
next = files
while next:
ret.append(next.contents)
if (next.contents.next == None):
break
next = next.contents.next

如果这些都对您没有帮助(可能没有 :D),我使用的 pymtp 库版本是使用 pip 下载的 0.0.6。

关于android - pymtp 在 python 3 上工作时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31975140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com