如何解决未找到文件,但文件确实存在,给出了完整路径等
文件确实存在,路径正确。我敢肯定。你们知道发生了什么吗?
这是我的代码:
with open(f'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{user.id}Istore.txt','r') as f:
lines = f.readlines()
title = lines[0]
desc = lines[1]
embed=discord.Embed(color=0x2f3136,description=desc,title=title)
with open(f'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{ctx.author.id}Istoreitems.txt','r') as f:
lines = f.readlines()
for line in lines:
line = line.replace("\n",'')
with open(f'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{ctx.author.id}Istore{line}','r') as f:
lines = f.readlines()
name = lines[0]
price = lines[2]
with open(f'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{channel.guild.id}.txt','r') as f:
lines = f.readlines()
currencyname = lines[1]
embed.add_field(title=name,value=price + " " + currencyname)
await ctx.send(embed=embed)
追溯:
Traceback (most recent call last):
File "C:\Users\jakec\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py",line 85,in wrapped
ret = await coro(*args,**kwargs)
File "C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\sf.py",line 221,in scmd
with open(os.path.join(f'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{ctx.author.id}Istore',line),'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\(A) Me\\Coding\\Python\\jcjakec\\Bots\\storefront\\storage\\564054910086283286Istore\\test'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\jakec\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py",line 903,in invoke
await ctx.command.invoke(ctx)
File "C:\Users\jakec\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py",line 859,in invoke
await injected(*ctx.args,**ctx.kwargs)
File "C:\Users\jakec\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py",line 94,in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\(A) Me\\Coding\\Python\\jcjakec\\Bots\\storefront\\storage\\564054910086283286Istore\\test'
希望你能帮忙!
解决方法
您需要通过将反斜杠 (\
) 加倍 (\\
) 来转义反斜杠 (ffprobe
)。否则,它们将被解释为特殊字符。
更简单的做法是在文件前面放一个 r。 例如 -
with open(r'C:\(A) Me\Coding\Python\jcjakec\Bots\storefront\storage\{user.id}Istore.txt','r') as f:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。