0

I have the following code:

from gettext import find
import urllib.request
import re

s = "here it must be a google forms URL"
formsHTML = "x"
response = "x"
quot = "",null,0,[["


def openURL ():
    print (response)
    print (quot)
    print (formsHTML)
    with urllib.request.urlopen(s) as f:
        formsHTML = f.read().decode('utf-8')

Somehow, when I try to access formsHTML it gives me back "UnboundLocalError: local variable 'formsHTML' referenced before assignment", but it does not happen the same with the other variables. I'm probably wrong, but shoudn't they be all defined on the global scope?

dipese
  • 91
  • 5
  • 2
    No, _reading_ a global variable is fine, but you can't modify it inside a function unless you separately declare it `global` – tripleee Oct 06 '22 at 13:03

0 Answers0