看板 [ Python ]
討論串[問題] 怎麼用 Python 寫出 switch 的功能?
共 11 篇文章
首頁
上一頁
1
2
3
下一頁
尾頁

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者flarehunter (Range)時間7年前 (2017/10/21 08:28), 編輯資訊
0
0
1
內容預覽:
試著用 context manager 實作. class ContextBase(object):. """The base of the context manager.""". def __init__(self, name):. self.name = name. def __enter__
(還有535個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者rexyeah (ccccccc)時間7年前 (2017/10/20 03:20), 編輯資訊
0
0
0
內容預覽:
增加原po說的倒車. # Add rollback processes if hitting failed. def init1():. return 'init1'. def init2():. return 'init2'. def init3():. return False. def rol
(還有433個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者zerof (貓橘毛發呆雕像)時間7年前 (2017/10/19 17:19), 編輯資訊
0
0
2
內容預覽:
class-based https://repl.it/JZn4/12. 但還是很醜......... 如果沒猜錯的話,外層應該會在 init() < 0 的時候再 release_process3() 。. 這樣的行為跟 switch-case 的 fall-through 其實沒啥關係....
(還有85個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者edwar (海邊的野孩子)時間7年前發表 (2017/10/19 16:47), 7年前編輯資訊
0
0
0
內容預覽:
我比較常用 return, 會像底下這樣寫:. ----. def init_phase():. releasers = []. def error(msg, releasers):. print( msg + ": initial failed.\n" ). while releasers:. (
(還有826個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者hl4 (Minimi)時間7年前 (2017/10/19 15:41), 編輯資訊
0
0
1
內容預覽:
曾經看過有人用 decorator 來寫這類功能,就憑印象寫寫看。. https://gist.github.com/zack1030/505a449678022981f7c384e9b0bde9aa. # 分別對應 init1, init2, init3 的結果. result = [True,
(還有588個字)
首頁
上一頁
1
2
3
下一頁
尾頁