Skip to main content
 首页 » 编程设计

python 通过 os.system 传递变量

2025年01月19日8虾米哥

<分区>

这会在我的目录中获取最新的 mp3 文件

new_file = [(os.path.getmtime(ft) , os.path.basename(ft)) 
            for ft in os.listdir(path) if ft.lower().endswith('.mp3')] 
 
new_file.sort() 

正在将最新的文件分配给我要播放的文件

playFile = new_file[0][1] 

获取文件的目录。

PlayfileDir = os.getcwd() + '\\' + str(playFile) 

正在播放文件。这是我收到错误“找不到 PlayfileDir”的地方。

os.system('start "PlayfileDir"')