Есть ли способ записать невидимую новую строку («\n») в текстовый файл с помощью Python? ⇐ Python
Есть ли способ записать невидимую новую строку («\n») в текстовый файл с помощью Python?
I'm trying to write to a text file using Python. The text file contains an existing line of text which is: "admin, adm1n" (admin being username, and adm1n being password). I added a new username and password (makay, makay1) on a new line, but when I try to re-call admin using the adm1n password, it turns out that the new line is being appended to "adm1n". Any suggestions would be helpful for creating an invisible newline.
Code snippet:
existing_users = open('user.txt', 'r+') new_username = input("Please create a new username: ") new_password = input("Please create a new password: ") existing_users.write(f"\n{new_username}, {new_password}") print(f"You have successfully registered the user {new_username}! Please remember to exit program.") existing_users.close() which outputs the text file as:
admin, adm1n makay, makay1 HOWEVER, when I print out the list of passwords, I see that it changes "adm1n" to "adm1n\n".
Please help!
Источник: https://stackoverflow.com/questions/781 ... sing-pytho
I'm trying to write to a text file using Python. The text file contains an existing line of text which is: "admin, adm1n" (admin being username, and adm1n being password). I added a new username and password (makay, makay1) on a new line, but when I try to re-call admin using the adm1n password, it turns out that the new line is being appended to "adm1n". Any suggestions would be helpful for creating an invisible newline.
Code snippet:
existing_users = open('user.txt', 'r+') new_username = input("Please create a new username: ") new_password = input("Please create a new password: ") existing_users.write(f"\n{new_username}, {new_password}") print(f"You have successfully registered the user {new_username}! Please remember to exit program.") existing_users.close() which outputs the text file as:
admin, adm1n makay, makay1 HOWEVER, when I print out the list of passwords, I see that it changes "adm1n" to "adm1n\n".
Please help!
Источник: https://stackoverflow.com/questions/781 ... sing-pytho
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как установить фокус на невидимую кнопку или само окно в QDialog (PyQt5)?
Anonymous » » в форуме Python - 0 Ответы
- 37 Просмотры
-
Последнее сообщение Anonymous
-