【发布时间】:2015-07-14 18:15:48
【问题描述】:
-
创建函数saveTxtIndividualTracks(track,folder,i)。基于python3.4.3和windows 7:
def saveTxtIndividualTracks(track,folder,i): f = open(folder+str(i)+'.txt','w+') for line in track: l=str(line[0])+','+str(line[1])+','+str(line[2])+'\n' f.write(l) f.close() -
使用函数:
saveTxtIndividualTracks(new,'E:/phoneTracks/'+track_name+'/',i)
当我运行代码时,我得到了这个错误:
FileNotFoundError: [Errno 2] 没有这样的文件或目录:'E:/phoneTracks/TA92903URN7ff/0.txt'
我在 E 中创建了文件夹 phoneTracks。我将 open() 函数与用于创建新文件的模式 'w+' 混淆了。为什么我会收到 FileNotFoundError?我能做些什么来解决它?
【问题讨论】:
-
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。
-
感谢@poke 的帮助。我会阅读 Morgan Thrapp 列出的这些有用的提示。
标签: python