python - 不知道如何修复此文件不存在错误
问题描述
文件 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)
推荐阅读
- c# - 将包含文本和图像的 PDF 文档附加到电子邮件 C# Windows 应用程序
- ui-automation - 是否存在一种搜索 IUIAutomationElement 指定名称是否包含空格的方法?
- javascript - 从 php json_encode() 调用 javascript 变量时出错,因为有 json 标签号
- mule - 如何在 Mule4 的 foreach 循环中检索元素?
- python - MySQL Python 连接器 - 更新不更新
- javascript - 使用 JQuery 更改具有相同类的所有 div 的 CSS 值,但前提是选中包含的复选框
- perl - 在 perl 中访问哈希元素的问题
- reactjs - 打印预览屏幕未显示我的 reactjs 应用程序的内容
- reactjs - 为什么 reat-admin 没有得到未加载记录(例如海报组件)的未定义异常?
- javascript - 使用套接字 io 运行 Javascript 文件时未加载