i get this error from my code i dont get it why it isnt working
with open("emails.txt",'r') as file:
for line in file:
grade_data = line.strip().split(':')
email = grade_data[0]
password = grade_data[1]
with open("emails_sorted.txt",'a') as file:
print(Fore.YELLOW + "Sorting email...")
file.write(email + '\n')
with open("passwords.txt",'a') as file:
print(Fore.YELLOW + "Sorting password...")
passwordspecial = password + '!'
file.write(passwordspecial + '\n')
print(Fore.GREEN + "Done!")
>Solution :
You’re opening emails_sorted.txt after you’ve iterated through the contents of the other text files. You can fix this by either saving the data read from emails.txt and iterating through it again when you open emails_sorted.txt and passwords.txt:
emails = []
passwords = []
with open("emails.txt", "r", encoding="utf-8") as file:
for line in file.readlines():
grade_data = line.strip().split(":")
emails.append(grade_data[0])
passwords.append(grade_data[1])
with open("emails_sorted.txt", "a", encoding="utf-8") as file:
print(Fore.YELLOW + "Sorting email...")
for email in emails:
file.write(email + "\n")
with open("passwords.txt", "a", encoding="utf-8") as file:
print(Fore.YELLOW + "Sorting password...")
for password in passwords:
passwordspecial = password + "!"
file.write(passwordspecial + "\n")
print(Fore.GREEN + "Done!")