如何在没有python的情况下打印文本文件
目前我的代码中有这个,但它的输出是这样的如何在没有python的情况下打印文本文件,python,text-files,txt,Python,Text Files,Txt,目前我的代码中有这个,但它的输出是这样的tenn\n我需要这样的tenn你可以这样读: 打开(“passwords.txt”、“r”)作为用户密码: 密码=用户密码。读取().splitlines() 这将首先读取整个文件,然后将其按行拆分。也可以将\n替换为零 open("usernames.txt", "r") open("passwords.txt", "r") with open("userna
tenn\n
我需要这样的tenn
你可以这样读:
打开(“passwords.txt”、“r”)作为用户密码:
密码=用户密码。读取().splitlines()
这将首先读取整个文件,然后将其按行拆分。也可以将\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)
这是因为您将每个用户名写在不同的行中。在这种情况下,您可以使用“Rejex”或创建数据库。这是错误的,因为
密码
将是一个字符串,在您的情况下没有任何“\n”。OP的passwords
变量是一个列表,每个元素的末尾都有'\n'。谢谢你,这是有效的。请接受答案,因为它对你有效。谢谢我不熟悉这个问题,你如何接受答案?只需单击我答案左侧的向上/向下投票下方的勾号。啊,谢谢,接受你的答案
with open("passwords.txt", "r") as user_passwords:
passwords = user_passwords.read().replace('\n', '')