txt文件字符数限制

txt file character limit

我希望我的代码从我的 txt 文件中读取字符数限制为 280 的行 如果该行超过 280 个字符,则应跳过该行

f = open('list.txt', 'r', encoding='utf-8').readlines()
for word in f:
    if word == "\n":
        continue
driver.find_element_by_xpath(message_xpatch).send_keys(word)

如果将驱动程序语句放在 if 语句中,长度检查应该会起作用:

f = open('list.txt', 'r', encoding='utf-8').readlines()
for word in f:
    word = word.strip()
    if 0 < len(word) <280:
        print(word)
        driver.find_element_by_xpath(message_xpatch).send_keys(word)