看板
[ Python ]
討論串[問題] 如何強制使用 with statement
共 2 篇文章
首頁
上一頁
1
下一頁
尾頁
內容預覽:
我的想法和推文一樣, 沒有必要強迫使用者用 context manager. 重點是文件要寫好, 如果使用者愛亂搞是他家的問題. 記得為什麼 Python 沒有 private member, 也沒什麼人愛用雙底線 trick 嗎?. We're all grown-ups here. :). 但如
(還有555個字)
內容預覽:
直覺的想法是在 __enter__ 的時候加個變數,執行其他函數的時候檢查,像這樣. class Test(object):. def __init__(self):. self._with_statement = False. def __enter__(self):. self._with_st
(還有218個字)
首頁
上一頁
1
下一頁
尾頁