1

好吧,众所周知,我正在尝试收集 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)

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

4

1 回答 1

2

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

outFile.write("Coordinate file: \n {} {} \n {} {}".format(x1, y1, x2, y2))
于 2013-07-09T19:53:19.977 回答