0

code can only run the first time. after that I found a mistake : TypeError: 'str' object is 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 is not callable

enough to make me confused: I want output : Baru = Bar1 Bekas = Beka2

har07
  • 88,338
  • 12
  • 84
  • 137
Khorud
  • 37
  • 1
  • 6

1 Answers1

1

I suspect you run this in Python interactive console. In this case the problem was due to your str variable, which created when the code run for the first time, hides the built-in function str() intended to be called when you run it the second time.

Just never use Python built-in function name as your variable name :

something_that_is_not_str = string.maketrans('us', '12')
result = var1.translate(strsomething_that_is_not_str)
print(result)
har07
  • 88,338
  • 12
  • 84
  • 137