Pygame "Can't seek in this data source"

Pygame "Can't seek in this data source"

项目结构如下:

app
    start.py
    src
        main.py
        __init__.py
    Pictures
        testing_001.png

start.py:

import src.main
src.main.main()

src.main:

def main():
    full_path = os.path.join(("Pictures","test_001.png"))
    try:
        image = pygame.image.load(full_path)
    except pygame.error as message:
        debug("Cannot load image:%s" % str(full_path))
        raise SystemExit(message)

我收到错误 "Can't seek in this data source",我做错了什么?,我做错了什么?

请注意,我正在使用 Python 3 并且 Pygame 是针对它构建的。 我检查了 pygame-cant-seek-in-this-data-source,但是,我认为我没有将元组传递给 pygame.image.load() 方法?

"I do not think I am passing a tuple to pygame.image.load()"

再次检查 :-)。 os.path.join 的参数应该是字符串,但您传递的是 tuple。此处的行为未由文档指定(我的猜测是这适合 "undefined behavior" 类别),但在这种情况下 os.path 似乎只是返回输入。

>>> os.path.join(("Pictures", "test_001.png"))
('Pictures', 'test_001.png')

您可能想要:

>>> os.path.join("Pictures", "test_001.png")
'Pictures/test_001.png'