string - Python str() : TypeError: 'str' object is not callable - the stop code -


this question has answer here:

code can run first time. after found mistake : typeerror: 'str' object not callable

create :

soup = beautifulsoup(r.content, "lxml")  berat = soup.find_all("dd", {"class": "pull-left m-0 border-none"})[0].text var1 = str(berat) str = string.maketrans('us', '12') result = var1.translate(str) print (result) 

output error

beka2 traceback (most recent call last): file "current.py", line 67, in <module> var1 = str(berat) typeerror: 'str' object not callable 

enough make me confused: want output : baru = bar1 bekas = beka2

i suspect run in python interactive console. in case problem due str variable, created when code run first time, hides built-in function str() intended called when run second time.

just never use python built-in function name variable name :

something_that_is_not_str = string.maketrans('us', '12') result = var1.translate(strsomething_that_is_not_str) print(result) 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -