[問題]關於移植 code from python 2.7 to 3.6

看板Python作者 (北極熊在英國)時間6年前 (2018/07/03 21:26), 編輯推噓4(4010)
留言14則, 7人參與, 6年前最新討論串1/2 (看更多)
請問一下於python 2.7 中 self.currentini = {'debug' : 'on'} def verify_currentlyini(self,(key,value)): self.currentini[str(key).split('$')[1]]=str(value) 但是更改python 3.6 self.currentini = {'debug' : 'on'} def verify_currentlyini(self,key,value): self.currentini[str(key).split('$')[1]]=str(value) TypeError: modify_currentlyini() missing 1 required positional argument: 'value' 請問大家該如何更改我的程式 ? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.200.200.9 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1530624366.A.149.html

07/03 21:33, 6年前 , 1F
參數改成 tuple嗎?
07/03 21:33, 1F

07/03 23:32, 6年前 , 2F
可以參考2to3怎麼改
07/03 23:32, 2F

07/04 09:14, 6年前 , 3F
和2 to 3 沒關係吧,method signature 整個不一樣了
07/04 09:14, 3F

07/04 09:27, 6年前 , 4F
推1F,改成(key, value)
07/04 09:27, 4F

07/04 11:18, 6年前 , 5F
不就是因為python3拿掉這種unpacking才要改嗎
07/04 11:18, 5F

07/04 11:19, 6年前 , 6F
不然他原本就是這樣寫阿
07/04 11:19, 6F

07/04 13:16, 6年前 , 7F
傳進去的東西就不能是tuple , 而要拆開來傳
07/04 13:16, 7F

07/04 14:26, 6年前 , 8F
改function容易還是改所有用到function的地方容易?
07/04 14:26, 8F

07/04 14:27, 6年前 , 9F
哪有什麼傳進去的東西就不能是tuple
07/04 14:27, 9F

07/04 15:08, 6年前 , 10F
function用一個參數接 在function裡面分別取出不就好了
07/04 15:08, 10F

07/04 22:33, 6年前 , 11F
你可以用decorator
07/04 22:33, 11F

07/12 08:42, 6年前 , 12F
多謝大家, python 3.7 傳進去的東西就不能是tuple
07/12 08:42, 12F

07/12 08:43, 6年前 , 13F
最後拆開來傳,結果沒有問題
07/12 08:43, 13F

07/12 08:43, 6年前 , 14F
文章代碼(AID): #1REtbk59 (Python)
文章代碼(AID): #1REtbk59 (Python)