我用Python 2.6.2在Linux上運行這個程序,它運行正常,返回的是十進制值,但是當我在Windows上的Python 2.7.2上運行它時,它不起作用,只是給了一段時間的空白空間,然後內存錯誤,但我不明白爲什麼......我需要它在Windows上運行其計算股票權益(ROE)的計劃。謝謝。此程序爲什麼在Linux Python Shell上運行,但不在Windows上運行?
運行該程序所需的CSV文件是here。 。
import csv
csvname = raw_input("Enter csv name: ")
sbuxfile = csv.reader(open(csvname), delimiter=',', quotechar='|')
# List of Data
row5, row8, row3, row7, avgequity, roe1, roe2 = ([] for i in range(7))
count = 0
# Grab data and numerical values from CSV.
for row in sbuxfile:
count += 1
if count == 8:
row8 = row
elif count == 5:
row5 = row
elif count == 3:
row3 = row
elif count == 7:
row7 = row
a = 1
# Perform calculations for average equity and ROE.
while a < 8 :
if a == 1:
avgequity.append(round(float(row8[a]),2))
roe1.append(float(row5[a])/float(row8[a]))
roe2.append((float(row5[a])/float(row3[a])) * (float(row3[a])/float(row7[a])) * (float(row7[a])/float(row8[a])))
else:
avgequity.append(round(float((row8[a]),2) + float(row8[a-1]))/2)
roe1.append(float(row5[a])/float(row8[a]))
roe2.append((float(row5[a])/float(row3[a])) * (float(row3[a])/float(row7[a])) * (float(row7[a])/((float(row8[a]) + float(row8[a-1]))/2)))
a+=1
print "\nAverage equity is " + str(avgequity) + "\n"
print "ROE method 1 is " + str(roe1) + "\n"
print "ROE method 2 is " + str(roe2)
你的輸入文件是什麼? – KevinDTimm
如果將open(csvname)更改爲open(csvname,'rb')',會發生什麼? –
我剛剛在上面添加了輸入文件,您可以下載並測試它。另外當你添加rb時,它仍然不能工作,只是同一個空白頁面,並在一段時間後內存錯誤。 – Goose