學習python出現的問題 類初始化

2021-07-13 11:01:16 字數 939 閱讀 4467

**如下:

class

song

(object):

def__int__

(self,lyrics):

self.lyrics = lyrics

defsingsong

(self):

for line in self.lyrics:

print line

"i don't want to get sued",

"so i'll stop singing."])

bulls = song(["they rally around the family",

"with pockets full of shells"])

bulls.singsong()

traceback (most recent call

last):

file "class.py", line 10, in

"so i'll stop singing."])

typeerror: object() takes no parameters

於是我考慮將物件建立的過程用以下**重寫:

"i don't want to get sued",

"so i'll stop singing."]

bulls = song()

bulls.lyrics = ["they rally around the family",

"with pockets full of shells"]

bulls.singsong()

顯示沒有問題,那就應該還是初始化函式__int__的問題。

定睛一看,應該是__init__才對。

故事告訴我們:要好好休息放鬆眼睛。

django模型類出現的問題

init missing 1 required positional argument on delete 問題產生的原因 在django2.0後,定義外來鍵和一對一關係的時候需要加on delete選項,此引數 為了避免兩個表裡的資料不一致問題,不然會報錯 解決方法 在後面引數裡新增on dele...

python 學習 初入爬蟲

1.爬取網頁內容 import urllib.request as ur import chardet as ct response ur.urlopen html response.read result ct.detect html encoding html html.decode resul...

Python出現編碼問題

原始碼 測試input 與raw input 的區別 input 返回的是整數 raw input 返回的是字串型別 input age input input your age raw input age raw input input your age print input age input...