Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用+;_Python_File Not Found - Fatal编程技术网

Python 使用+;

Python 使用+;,python,file-not-found,Python,File Not Found,错误: if 'privnote.com' in message.content: if privnote_sniper == True: start = datetime.datetime.now() code = re.search('privnote.com/(.*)', message.content).group(1) link = 'https://privnote.com/' + code try:

错误:

 if 'privnote.com' in message.content:
     if privnote_sniper == True:
         start = datetime.datetime.now()
         code = re.search('privnote.com/(.*)', message.content).group(1)
         link = 'https://privnote.com/' + code
         try:
             note_text = pn.read_note(link)
         except Exception as e:
             print(e)
         with open(f'Privnote/{code}.txt', 'a+') as data:
             print(f"\n{Fore.GREEN}{time} - Privnote Sniped" + Fore.RESET)
             elapsed = datetime.datetime.now() - start
             elapsed = f'{elapsed.seconds}.{elapsed.microseconds}'
             PrivnoteInfo(elapsed, code)
             data.write(note_text)
             if notification:
                 toaster.show_toast("Sniper",
                                    "Privnote sniped! Look into console",
                                    icon_path="./drop.ico",
                                    duration=7)

为什么它说即使我使用
a+
,也没有这样的文件?如果文件不存在,不应该创建该文件吗?

如果您试图创建的文件已作为指向不存在目录中文件的符号链接存在,则可能会发生这种情况。更可能的问题是,
Privnote
目录不存在
open()
将只创建文件,而不会创建目录。@Barmar-看起来用户是在Windows上,而不是在Linux上;请参阅on_Message中错误文件“C:\Users\puffy\Desktop\PuffySB\main.py”第497行中的路径。如果您确实在Windows计算机上,则会混淆文件路径的正斜杠和反斜杠。尝试将您的open调用更改为:使用open(f'Privnote\\{code}.txt',a+')作为数据:@LouieC Windows允许向前和向后斜杠,并且不介意将它们混合使用。
File "C:\Users\puffy\Desktop\PuffySB\main.py", line 497, in on_message
with open(f'Privnote/{code}.txt', 'a+') as data:
FileNotFoundError: [Errno 2] No such file or directory: 'Privnote/0e77iYWk#6UEmMSGDn.txt'