[英]How can I split wordlist from a file
大家好,我想從選定的文件中拆分單詞,但它返回 ['0']
在我的文本文件中,我有 email:password 這樣的 email@gmail.com:password
我想把它們分成一個列表
電子郵件 = ['email@gmail.com'] 密碼 = ['密碼]
path = easygui.fileopenbox()
print(path)
username = []
passwords = []
with open(path, 'r') as f:
lineCount = len(f.readlines())
lines = f.readlines()
for line in str(lineCount):
username = re.split(':',line)
password = re.split(':',line)
嘗試這樣做:
import re
usernames = []
passwords = []
with open(path, 'r') as f:
for line in f:
line = line.strip()
match = re.match(r'^.*?@\w+?\.\w+?:', line)
if match:
username = line[:match.end() - 1]
password = line[match.end():]
usernames.append(username)
passwords.append(password)
打開文件並一次讀取一行。 在冒號上拆分應該給出兩個標記的行(假設文件格式如問題中所述)。 Append 每個令牌到相應的列表。
usernames = []
passwords = []
with open(path) as data:
for line in map(str.strip, data):
try:
pos = line.index(':')
usernames.append(line[:pos])
passwords.append(line[pos+1:])
except ValueError:
pass # ignore this line as no colon found
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.