第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

TypeError:'str'對(duì)象不可調(diào)用(Python)

TypeError:'str'對(duì)象不可調(diào)用(Python)

慕妹3146593 2019-07-30 17:00:33
TypeError:'str'對(duì)象不可調(diào)用(Python)碼:import urllib2 as uimport os as o inn = 'dword.txt'w = open(inn)z = w.readline()b = w.readline()c = w.readline()x = w.readline()m = w.readline()def Dict(Let, Mod):     global str     inn = 'dword.txt'     den = 'definitions.txt'     print 'reading definitions...'     dell =open(den, 'w')     print 'getting source code...'     f = u.urlopen('http://dictionary.reference.com/browse/' + Let)     a = f.read(800)     print 'writing source code to file...'     f = open("dic1.txt", "w")     f.write(a)     f.close()     j = open('defs.txt', 'w')     print 'finding definition is source code'     for line in open("dic1.txt"):         if '<meta name="description" content=' in line:            j.write(line)     j.close()     te = open('defs.txt', 'r').read().split()     sto = open('remove.txt', 'r').read().split()     print 'skimming down the definition...'     mar = []     for t in te:         if t.lower() in sto:             mar.append('')         else:              mar.append(t)     print mar     str = str(mar)     str = ''.join([ c for c in str if c not in (",", "'", '[', ']', '')])     defin = open(den, Mod)     defin.write(str)     defin.write('                 ')     defin.close()     print 'cleaning up...'     o.system('del dic1.txt')     o.system('del defs.txt')Dict(z, 'w')Dict(b, 'a')Dict(c, 'a')Dict(x, 'a')Dict(m, 'a')print 'all of the definitions are in definitions.txt'第一次Dict(z, 'w')工作然后第二次出現(xiàn)錯(cuò)誤:Traceback (most recent call last):   File "C:\Users\test.py", line 64, in <module>     Dict(b, 'a')   File "C:\Users\test.py", line 52, in Dict     str = str(mar)TypeError: 'str' object is not callable有人知道為什么嗎?
查看完整描述

3 回答

?
catspeake

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊

這就是問題:

global str

str = str(mar)

你正在重新定義什么str()意思。str是字符串類型的內(nèi)置Python名稱,您不想更改它。

為局部變量使用不同的名稱,并刪除該global語句。


查看完整回答
反對(duì) 回復(fù) 2019-07-30
?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊

雖然不在您的代碼中,但另一個(gè)難以發(fā)現(xiàn)的錯(cuò)誤是%在嘗試字符串格式化時(shí)缺少該字符:

"foo %s bar %s coffee"("blah","asdf")

但它應(yīng)該是:

"foo %s bar %s coffee"%("blah","asdf")

失蹤%將導(dǎo)致相同的結(jié)果TypeError: 'str' object is not callable。


查看完整回答
反對(duì) 回復(fù) 2019-07-30
?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

另一種情況:使用非透明調(diào)用失敗__repr__的對(duì)象的功能進(jìn)行混亂format()。

在我們的例子中,我們使用了一個(gè)@property裝飾器__repr__并將該對(duì)象傳遞給了一個(gè)format()。該@property裝飾使__repr__被打開成一個(gè)字符串,其然后導(dǎo)致對(duì)象str對(duì)象是不可調(diào)用錯(cuò)誤。


查看完整回答
反對(duì) 回復(fù) 2019-07-30
  • 3 回答
  • 0 關(guān)注
  • 1948 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)