TypeError: 'str' object is not callable (Python)

后端 未结 16 1156
忘了有多久
忘了有多久 2020-11-22 11:44

Code:

import urllib2 as u
import os as o
inn = \'dword.txt\'
w = open(inn)
z = w.readline()
b = w.readline()
c = w.readline()
x = w.readline         


        
16条回答
  •  醉酒成梦
    2020-11-22 12:09

    While not in your code, another hard-to-spot error is when the % character is missing in an attempt of string formatting:

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

    but it should be:

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

    The missing % would result in the same TypeError: 'str' object is not callable.

提交回复
热议问题