我如何在 python 中打印没有 \n 的文本文件
how can i print text files without \n in python
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)
我的代码目前有这个,但它输出是这样的tenn\n
我需要这样tenn
你可以这样阅读:
with open("passwords.txt", "r") as user_passwords:
passwords = user_passwords.read().splitlines()
这会先读取整个文件,然后按行拆分它们。
也可以将\n替换为空
with open("passwords.txt", "r") as user_passwords:
passwords = user_passwords.read().replace('\n', '')
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)
我的代码目前有这个,但它输出是这样的tenn\n
我需要这样tenn
你可以这样阅读:
with open("passwords.txt", "r") as user_passwords:
passwords = user_passwords.read().splitlines()
这会先读取整个文件,然后按行拆分它们。
也可以将\n替换为空
with open("passwords.txt", "r") as user_passwords:
passwords = user_passwords.read().replace('\n', '')