2
open("usernames.txt", "r")
open("passwords.txt", "r")

with open("usernames.txt", "r") as users:
    usernames = users.readlines()

with open("passwords.txt", "r") as user_passwords:
    passwords = user_passwords.readlines()

print(usernames)
print(passwords)

i currently have this for my code, but it outputs it like this tenn\n i need to have it like this tenn

tenn
  • 27
  • 1
  • 4

2 Answers2

1

You could read like this:

with open("passwords.txt", "r") as user_passwords:
    passwords = user_passwords.read().splitlines()

This reads the entire file first and then splits them by lines.

Ajay Maity
  • 740
  • 2
  • 8
  • 17
0

Can also replace the \n with nothing

with open("passwords.txt", "r") as user_passwords:
    passwords = user_passwords.read().replace('\n', '')
Apo
  • 338
  • 1
  • 9
  • This is wrong, because `passwords` would be a single string without any '\n' in your case. OP's `passwords` variable is a list with each element having '\n' at the end. – Ajay Maity Dec 24 '20 at 10:58