2013-07-09 68 views
1

好吧我正在嘗試收集x,y座標,因爲大家都知道,我正在使用保存功能將x,y保存爲文本文件。這裏是我得到Python TypeError,給出了一個參數6。

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) 

任何想法如何解決這一問題?

回答

2

.write只需要一個參數,首先格式化字符串:

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

不要'{}'需要索引?說0,1 ... –

+0

@EdgarAroutiounian在Python 2.6中,是的,但不是在Python 2.7 –

+0

它的工作! - 謝謝@JonClements! – CodeMonkeyAlx

相關問題