0

I have the following Code:

    import urllib.request, json
    for i in range(10):
    with urllib.request.urlopen(baselink[i]) as url:
        data[i] = json.loads(url.read().decode())

My baselink[i] are different URL strings. I am having difficulties to get my loop to run. Normally I am used to loops of the following type:

    for i in range(10):
        data[i] = something[i]

But I can't figure out how to get the loop to properly use the following "with ... as"-part:

    with urllib.request.urlopen(baselink[i]) as url:

The error message is : "IndentationError: expected an indented block" . I tried to put the part after ":" in brackets but that didn't solve the problem. What I need as result is the outcomes of data[1], data[2], data[3], etc. ...

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Joshua Zecha
  • 141
  • 1
  • 8
  • 3
    The error have nothing to do with the `with` statement. Read it again! Especially the first word: "IndentationError". You do know that blocks in Python uses indentation to denote scope? – Some programmer dude Jan 09 '18 at 13:08
  • Thanks for the comment. I have not come across any indentation issues yet, so this was new to me. – Joshua Zecha Jan 09 '18 at 13:17

0 Answers0