[問題] print畫面資料 寫出一個檔
HI all
最近在修課時發現常常需要多次反覆執行計算
所以在思考 有沒有辦法讓其 設定
1.設定重複執行幾次
2.結果將每次結果寫出 (已解決:)
還請大大可以指點 謝謝大家
=======================================================
def Queens():
status =
[0,1,2,3,4,5,6,7] #初始皇后都在對角線
#當存在衝突個數大於0時,循環球解最佳後繼,直到找到最後一個皇后
while get_numof_conflict(status) > 0:
status = hill_climbing(status)
print status
print get_numof_conflict(status)
f = open("twice.txt", "a")
sys.stdout = f
print "the answer is"
print
print status
time.sleep(2)
tEnd = time.time()#計時結束
print "It cost %f sec" % (tEnd - tStart)#會自動做近位
#列印結果
file = open('data.txt','w+')
# print>>file
# file.close()
===========================================================
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.254.66.133
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1544281299.A.3F7.html
推
12/09 10:34,
6年前
, 1F
12/09 10:34, 1F
謝謝 s大 我換了一個作法 將print內容直接寫在txt檔
目前還剩 指定他 重複執行幾次
※ 編輯: newdas (111.254.66.133), 12/09/2018 15:06:29
※ 編輯: newdas (111.254.66.133), 12/09/2018 15:46:32
Python 近期熱門文章
PTT數位生活區 即時熱門文章