我有一個Python代碼的特定情況。每次運行代碼時,RAM內存都會增加,直到達到1.8 GB並崩潰。Python 2.7.3內存錯誤
import itertools
import csv
import pokersleuth
cards = ['2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', 'Ts', 'Js', 'Qs', 'Ks', 'As', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah', '2c', '3c', '4c', '5c', '6c', '7c', '8c', '9c', 'Tc', 'Jc', 'Qc', 'Kc', 'Ac', '2d', '3d', '4d', '5d', '6d', '7d', '8d', '9d', 'Td', 'Jd', 'Qd', 'Kd', 'Ad']
flop = itertools.combinations(cards,3)
a1 = 'Ks' ; a2 = 'Qs'
b1 = 'Jc' ; b2 = 'Jd'
cards1 = a1+a2
cards2 = b1+b2
number = 0
n=0
m=0
for row1 in flop:
if (row1[0] <> a1 and row1[0] <>a2 and row1[0] <>b1 and row1[0] <>b2) and (row1[1] <> a1 and row1[1] <>a2 and row1[1] <>b1 and row1[1] <>b2) and (row1[2] <> a1 and row1[2] <> a2 and row1[2] <> b1 and row1[2] <> b2):
for row2 in cards:
if (row2 <> a1 and row2 <> a2 and row2 <> b1 and row2 <> b2 and row2 <> row1[0] and row2 <> row1[1] and row2 <> row1[2]):
s = pokersleuth.compute_equity(row1[0]+row1[1]+row1[2]+row2, (cards1, cards2))
if s[0]>=0.5:
number +=1
del s[:]
del s[:]
print number/45.0
number = 0
n+=1
'del s [:]'的意圖是什麼?這是刪除一個新創建的副本。 –
試圖刪除列表,因爲我在哪裏數據去。我不保存任何東西,只是打印結果。 –
聖牛,誰寫這意大利麪條。另外,'pokersleuth.compute_equity()'做了什麼?你不需要刪除列表,btw ... – kreativitea