欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python | pygame.mixer.music.load()函数使用相对路径

程序员文章站 2022-03-02 23:26:56
...
import os,sys
APP_FOLDER = os.path.dirname(os.path.realpath(sys.argv[0]))

# method one
full_path=os.path.join(APP_FOLDER,"your_file_name")
pygame.mixer.music.load(full_path)

# method two: change current working directory
os.chdir(APP_FOLDER)
pygame.mixer.music.load('your_file_name')