python - 如何从文本文件中删除项目或字符串
问题描述
我已经打开了一个文本文件作为 tf 我想从 txt.file 中删除例如文本“Hello” 如何做到这一点是最快的方法?我要删除的文本保存为 "+" , list_of_numbers
import os
from tkinter import *
from tkinter import filedialog
import selenium
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium import webdriver
import contextlib as textmanager
PATH= "C:\Program Files (x86)\chromedrivers\chromedriver.exe"
driver= webdriver.Chrome(PATH)
list_of_numbers=[]
full_list_of_numbers_work=[]
在这里,我将文件打开为 tf
def openFile():
tf = filedialog.askopenfilename(
initialdir="C:/Users/MainFrame/Desktop/",
title="Open Text file",
filetypes=(("Text Files", "*.txt"),)
)
pathh.insert(END, tf)
with open(tf) as f: # use context manager
for line in f:
txtarea.insert(END, line)
line = line.strip()
if line:
list_of_numbers.append(int(line))
ws = Tk()
ws.title("PythonGuides")
ws.geometry("400x450")
ws['bg']='#fb0'
txtarea = Text(ws, width=40, height=20)
txtarea.pack(pady=20)
pathh = Entry(ws)
pathh.pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="Open File",
command=openFile
).pack(side=RIGHT, expand=True, fill=X, padx=20)
ws.mainloop()
driver.get("https://login.yahoo.com/?.lang=en-US&src=homepage&.done=https%3A%2F%2Fwww.yahoo.com%2F&pspid=2023538075&activity=ybar-signin")
input_field= driver.find_element_by_id("login-username")
button_for_next= driver.find_element_by_id("login-signin")
counting=0
这是我想从文件中删除文本的地方,我想要一种快速的方法
while counting !=len(list_of_numbers):
input_field.send_keys("+", list_of_numbers[counting])
button_for_next.click()
if len(driver.find_elements_by_css_selector("p[data-error]")) > 0:
#remove the item which is "+" , list_of_numbers[counting]
解决方案
推荐阅读
- ios - Swift:从嵌套数组中快速解码 JSON 响应中的未知上下文
- amazon-web-services - 如何在外部在 Amazon Glue 中创建数据目录?
- tensorflow - 关于我的屏幕截图,我的 GPU 或 CPU 是否正在运行?
- loadrunner - 录制选项中存在授权标头但不重播
- jupyter-notebook - jupyter notebook markdown 代码单元格背景颜色
- android - CardView 内的嵌套布局与父端重叠
- django - 方法 GET Django 和 Angular 错误 500 内部服务器
- python - 如何提高验证准确率?
- c++ - 使用 CMake 构建 zLib
- php - 责任链实施