【问题标题】:Pygame "Can't seek in this data source"Pygame“无法在此数据源中搜索”
【发布时间】:2015-01-24 05:49:28
【问题描述】:

项目结构如下:

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)

我收到错误“无法在此数据源中查找”,我做错了什么?我做错了什么?

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

【问题讨论】:

    标签: python python-3.x pygame


    【解决方案1】:

    “我认为我没有将元组传递给pygame.image.load()

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

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

    你可能想要:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多