【发布时间】:2017-08-07 21:55:06
【问题描述】:
我正在使用 freesound API 搜索和下载声音片段,以用于训练神经网络。当脚本遇到名称中带有特殊字符的文件时,它会报错并且脚本将停止。我想下载它遇到的带有特殊字符的文件并继续搜索。
这是我的代码:(API 密钥在,暂时取出)
import freesound, sys,os
client = freesound.FreesoundClient()
client.set_token("API KEY","token")
results = client.text_search(query="dog", page_size=150,
fields="id,name,previews")
for sound in results:
if "/" or "\\" or '.' not in sound.name:
sound.retrieve_preview(".", sound.name+".mp3")
print(sound.name)
错误代码:
FileNotFoundError: [Errno 2] No such file or directory: '.\\Dog eating Neck
of Goose / Chewing / Breaking Bones.mp3'
【问题讨论】:
-
if "/" or "\\" or '.' not in sound.name: 没有做你认为的事情。只是True