How can I split wordlist from a file
Question:
Hello guys I want to split words from a selected file but It returns [‘0’]
in my text file I have email:password like this [email protected]:password
I want to split them into a list
emails = [’[email protected]’]
passwords = [‘password]
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)
Answers:
Try doing it this way:
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)
Open the file and read one line at a time. Split the line on colon which should give two tokens (assuming the file format is as stated in the question). Append each token to the appropriate list.
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
Hello guys I want to split words from a selected file but It returns [‘0’]
in my text file I have email:password like this [email protected]:password
I want to split them into a list
emails = [’[email protected]’]
passwords = [‘password]
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)
Try doing it this way:
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)
Open the file and read one line at a time. Split the line on colon which should give two tokens (assuming the file format is as stated in the question). Append each token to the appropriate list.
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