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)
Asked By: dracoludio draco

||

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)
Answered By: Alexander

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
Answered By: Vlad
with open("test") as file:
    content=file.read()
    email,password=content.split(":")
print(email,"=======",password)  

code

Answered By: samadpls
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.