簡體   English   中英

不知道如何修復此文件不存在錯誤

[英]Don't know how to fix this file doesn't exist error

該文件combo.txt存在,但是當我運行該程序時出現錯誤。 我嘗試多次運行它,但是它給出了相同的錯誤,我不知道該怎么辦。

def failed(email, password):
    pass
def passed(email, password):
    pass
def checker(email, password):
    pass
combos_name = input("please enter combos name: ")
combos = open(combos_name, "r").readLines()
arrange = [lines.replace("\n", "") for lines in combos]
for lines in arrange:
    lines.split(":")
    print(lines)

錯誤:

C:\Checker\venv\Scripts\python.exe C:/Checker/checker.py
please enter combos name: combo.txt
Traceback (most recent call last):
  File "C:/Checker/checker.py", line 15, in <module>
    combos = open(combos_name, "r").readLines()
FileNotFoundError: [Errno 2] No such file or directory: 'combo.txt'

Process finished with exit code 1

這是一種調用文件對話框以選擇文件或鍵入文件的方法:

from Tkinter import Tk, filedialog

def failed(email, password):
    pass
def passed(email, password):
    pass
def checker(email, password):
    pass
root = Tk()
root.withdraw()

#combos_name = input("please enter combos name: ")

combos_name = filedialog.askopenfilename(initialdir = "./", title = "Select file")

combos = open(combos_name, "r").readlines()
arrange = [lines.replace("\n", "") for lines in combos]
for lines in arrange:
    lines.split(":")
    print(lines)

您的文件似乎不存在,或者在當前目錄中不存在。 您可以確保您的文件code.txt與您正在執行的代碼位於同一目錄中。

若要解決此問題,您可以嘗試將abolute路徑傳遞給code.txt文件。

另外,您可以使用os模塊檢查文件是否存在或檢查當前目錄。

import os
print(os.path.exists('code.txt'))  # check if code.txt exists
print(os.getcwd())  # check current directory
print(os.listdir())  # list all files in current directory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM