Python 如何获得新线路

Python 如何获得新线路,python,Python,如何在输出文件上打印新行?当我尝试用/n添加新行时,它只打印/n 这就是我目前所拥有的 `` inputFile=opendemofile1.txt,r outFile=openJi string = line.split(',') go =(string)[3::] bo = [float(i) for i in go] total = sum(bo) pine = ("%8.2f"%total) name = string[2] + ","

如何在输出文件上打印新行?当我尝试用/n添加新行时,它只打印/n

这就是我目前所拥有的

`` inputFile=opendemofile1.txt,r outFile=openJi

    string = line.split(',')

    go =(string)[3::]
    bo = [float(i) for i in go]
    total = sum(bo)
    pine = ("%8.2f"%total)
    name = string[2] + "," + " " + string[1]

    kale = (string[0] + " " + name + " " + "/n")

    se)
当前结果


您需要使用\n,而不是/n。所以这一行:

kale = (string[0] + " " + name + " " + "/n")
应该是:

kale = (string[0] + " " + name + " " + "\n")

也请考虑使用STR格式化程序,所以所有这些行:

go =(string)[3::]
bo = [float(i) for i in go]
total = sum(bo)
pine = ("%8.2f"%total)
name = string[2] + "," + " " + string[1]
kale = (string[0] + " " + name + " " + "/n")
str1 = ''.join(kale)
str2 = ''.join(pine)
outFile.write(str1 + " " + str2 + " ")
将成为:

outFile.write("{} {} {:8.2f}\n".format(string[0], string[2] + ", " + string[1], sum(bo))
可能重复的
outFile.write("{} {} {:8.2f}\n".format(string[0], string[2] + ", " + string[1], sum(bo))