python - 从 txt 文件中跳过一行
问题描述
您好,我想从我的 txt 文件中发送一个随机密钥,如果有空行则跳过我的问题是我的代码只发送一个字母而不是整行
这是我的代码
with open('list.txt', 'r', encoding='utf-8') as f:
file = f.readline()
for word in file:
if not word.strip():
continue
elif not 0 < len(word) < 280:
continue
sleep(1)
driver.find_element_by_css_selector('div[role="textbox"][data-testid="tweetTextarea_0"]').send_keys(random.choice(word))
sleep(1)
解决方案
推荐阅读
- json - 使用 Swift 获取 JSON 中的第一个元素
- python - 将元素放入 3D 网格的最快方法
- python - 如何在 python pandas 中重塑数据框
- docker - Docker - 在执行容器时挂载卷
- apache-camel - 无法在 apache camel 中处理正文中的空值
- python - 使用python将cassandra sstable从gcloud复制到s3
- nginx - 通过 https 的 socket.io 问题,使用 nginx 作为代理
- java - 用美元符号替换字符串中的最后一个点
- gradle - 使用 Gradle 进行转码
- c++ - 当且仅当它不会导致重新定义错误时,如何定义新的函数/结构/类?