【发布时间】:2016-03-23 06:04:04
【问题描述】:
所以基本上我有这个代码:
try:
fhanddate = open('AAPLprice.txt')
except:
print 'Could not open file - closing application'
exit()
stock_date = []
for line in fhanddate:
p = line.strip()
q = p.split(',')
r = q[0:]
stock_date.append(r)
for line in stock_date:
pass
last = line
print last[0]
try:
fhanda = open('AAPLprice.txt')
except:
print 'Could not open file - closing application'
exit()
stock_priceA = []
for line in fhanda:
p = line.strip()
q = p.split(',')
r = q[-1:]
stock_priceA.append(r)
print max(stock_priceA)
我的输出结果是:
2015-07-21
['129.606052']
所以我想知道如何将这两个输出结合起来,结果得到:2015-07-21 129.606052
当我尝试将它们组合起来时,我得到“TypeError: cannot concatenate 'str' and 'list' objects”错误
【问题讨论】:
-
我认为这是 Python2?另外,您能否附上一个 AAPLprice.txt 的样本?例如。线条是什么样子的?
-
@cricket_007 是 2.7
-
你是如何尝试组合字符串和列表的?如果首先使用 str(list) 将列表转换为字符串,则可以将它们连接在一起
-
上面的行有很多事情要做。但只需将
,放在您的第一个打印语句之后,将[0]放在最后一个之后。 -
打印最后一行的第一列和第二列的最大值是否有某种原因?所有第一列的值都相同吗?
标签: python list python-2.7 readlines