1. 程式人生 > >python報錯: xxx takes 1 positional argument but 2 were given

python報錯: xxx takes 1 positional argument but 2 were given

開始時是發現按了按鈕之後介面閃退,無報錯資訊。debug之後出現exception:takes 1 positional argument but 2 were given
原因:
這裡寫圖片描述

不能忽略這個self,如果寫成def weight_variable(shape):,後面再給這個函式傳參,python就會覺得你傳了兩個引數(第一個預設是self)