如何删除输出中的这些括号?

2024-05-15 13:47:16 发布

您现在位置:Python中文网/ 问答频道 /正文

这可能是个愚蠢的问题,但我对Python还不太了解。我正在编写这段代码,它假定接受X值的输入和Y值的输入,将它们写入文件并在屏幕上打印(稍后我将使用matplotlib打印它们)。但我得到了我的输出两个括号,我不想他们在那里。下面是代码(我正在用Python 3.4在Ubuntu上编程):

xcoord = open("x.dat","w")
xinput = input('Enter with the values for x separeted by coma (ex: 10,25,67):')
xcoord.write(str(xinput))
xcoord.close()
ycoord = open("y.dat","w")
yinput = input('Enter with the values for y separeted by coma (ex: 10,25,67):')
ycoord.write(str(yinput))
ycoord.close()

xcoord = open("x.dat","r")
listax = xcoord.read().split(',')
ycoord = open("y.dat","r")
listay = ycoord.read().split(',')
print listax
print listay

我在文件中得到的输出类似于(10,20,30),而我在屏幕上得到的输出类似于['(10','20','30)'。我怎样才能去掉这些括号?


Tags: 文件the代码forinput屏幕withopen