I have a text file called Accounts.txt. It stores usernames and passwords in plain text like this:
Username Password
Username2 Password2
Username3 Password3etc
My code is this:
with open("Accounts.txt", "a+") as Accounts:
Accounts.write("LoginName") #write password to Accounts.txt
Accounts.write(" ")
Accounts.write("Password") #write password to Accounts.txt
Accounts.write("\n") #create new line
Accounts.seek(0) #start reading from start of txt
lines = str(Accounts.readlines())
cleanedlines = lines.replace("\n","")
print(cleanedlines, end = "")
The output of running this is this:
C:\Users\drago\Desktop\PythonPractice\venv\Scripts\python.exe C:\Users\drago\Desktop\PythonPractice\FileAppendTest.py
['mrwong poop123\n', 'edible_man weeeeed420\n', 'portarossa pigsanimalsgood\n', 'LoginName Password\n', 'LoginName Password\n', 'LoginName Password\n', 'LoginName Password\n', 'LoginName Password\n', 'LoginName Password\n']
Process finished with exit code 0
How do I remove all the \n
?
I have tried lines.replace("\n","")
and it did not work.
Edit: Also using strip and rstrip has not worked. Im on pycharm.