Python TypeError,给出一个参数六。

时间:2013-07-09 19:50:22

标签: python-2.7 typeerror

好吧我正在尝试收集你所知道的x,y坐标,我正在研究保存功能,将x,y保存到文本文件中。这是我得到的

x1 = raw_input("What is x1: ")
y1 = raw_input("What is y1: ")
x2 = raw_input("what is x2: ")
y2 = raw_input("what is y2: ")
outFile = open("c:\\users\zilvarael\Desktop\coord_man.txt", "wt")
outFile.write("Coordinate file: \n", x1, y1, "\n", x2, y2)

以下是我面临的错误:

    outFile.write("Coordinate file: \n", x1, y1, "\n", x2, y2)
    TypeError: function takes exactly 1 argument (6 given)

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

.write只接受一个参数,首先格式化字符串:

outFile.write("Coordinate file: \n {} {} \n {} {}".format(x1, y1, x2, y2))