python file.write() 不创建新行

python file.write() does not create new line

我是 Python 的新手,正在学习如何 write/read 文本文件 here 的教程。但是我 运行 遇到一个问题,在写入文件时,它不会创建另一行,而是直接在第一行之后写入。我在下面附上了我的代码,非常感谢任何帮助!

   import os
import sys
def generate_cdat():
    file = open("documents/pytho/login/cdat.txt", "w")
    file.write("username[usr]")
    file.write("userpass[1234]")
    file.close()
def getCredentials(checkUsrName, checkUsrPass):
    file = open("documents/pytho/login/cdat.txt", "r")
    recievedUsrName = file.readline(1)
    recievedUsrPass = file.readline(2)
    if checkUsrName in recievedUsrPass:
        print("recieved username")
print("started program")
print("checking for constant data file")
path = "cdat.txt"
if os.path.exists(path):
    print("Constant data found, setting up")
else:
    print("Constant data not found, creating constant data.")
    generate_cdat()
print("starting login")
logingIn = True
while logingIn == True:
    getUsrName = input("Enter username: ")
    getUsrPass = getpass.getpass("Enter password: ")
    checkCredentials(getUsrName, getUsrPass)

再次感谢, 最大!

尝试在字符串末尾添加 \n