0

I'm working on this code ("https://dlab.berkeley.edu/blog/scraping-new-york-times-articles-python-tutorial"). I upgrade the code but I'm having a problem with this code

Amnesty_all = ()
for i in range (1980, 2014):
  print ("processing" + str(i) +"...")
  Amnesty_year = get_articles(str(i), 'Amnesty International')
  Amnesty_all  = Amnesty_all + Amnesty_year

this is the error

TypeError                                 Traceback (most recent call last)
<ipython-input-45-9d931b0be5bb> in <module>()
      1 Amnesty_all = ()
      2 for i in range (1980, 2014):
----> 3   print ("processing" + str(i) +"...")
      4   Amnesty_year = get_articles(str(i), 'Amnesty International')
      5   Amnesty_all  = Amnesty_all + Amnesty_year

TypeError: 'str' object is not callable

Do you have any idea how to resolve this ?

Ched
  • 1
  • The above code does not seem to have any errors, if this is not all of your code, it would be nice to give us some more info, maybe you defined a `str` before? – Countour-Integral Aug 01 '20 at 23:27
  • Yes, you've accidentally reassigned either `print` or `str` somewhere before this. – Carcigenicate Aug 01 '20 at 23:35
  • @Carcigenicate yes it's not my code sorry during the redaction of the question i deleted some informations.the code is from this source https://dlab.berkeley.edu/blog/scraping-new-york-times-articles-python-tutorial – Ched Aug 03 '20 at 21:57

1 Answers1

0

As I see, you should try to replace:

print ("processing" + str(i) +"...")

With:

print ("processing {}...".format(i))

Based on previous issues, looks like you created str variable or smth :)

sortas
  • 1,527
  • 3
  • 20
  • 29
  • Hi I followed your advice `Amnesty_all = [] for i in range(1980,2014): print ("processing {}...".format(i)) Amnesty_year = get_articles(str(i),"amnesty") Amnesty_all = Amnesty_all + Amnesty_year print(type(i))` but the now I'm receiving this error **TypeError: must be str, not bytes** for the line `Amnesty_year = get_articles(str(i),"amnesty")`. Any advice ? – Ched Aug 06 '20 at 21:53
  • What version of Python are you using and what `get_articles` function does? – sortas Aug 06 '20 at 22:13
  • I'm using Colab so if using python Python 3.6.9 and Python 2.7.17, The function **get_articles** accepts a year in string format (e.g.'1980') and a query (e.g.'Amnesty International') and it will return a list of parsed articles (in dictionaries) for that year. – Ched Aug 08 '20 at 16:17
  • If you're getting `bytes` error it means that you messed up your Python2/3 collab. Also, you can't convert bytes to string using `str`, bytes need to be `decode`d. – sortas Aug 08 '20 at 16:43
  • Thank you for your suggestion and it partialy worked ` Amnesty_all = () for i in range (1980, 2014): theta = b"i".decode("utf8") print ("processing".format(theta)) Amnesty_year = get_articles(theta, 'Amnesty International') Amnesty_all = Amnesty_all + Amnesty_year` but i'm receiving this error TypeError: 'str' object is not callable – Ched Aug 08 '20 at 17:49