首页 > 解决方案 > 不知道如何修复此文件不存在错误

问题描述

文件 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

标签: pythonpython-2.7

解决方案


这是一种调用文件对话框来选择文件和输入文件的方法:

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)

推荐阅读