For code 1 to work , you need to import the urllib.parse module, not the quote function. Thus, you can reference the quote function with the full qualifier of the module. With this approach, you can use any function defined in the parse module:
 import urllib.parse s = urllib.parse.quote('"') print(s) 
code 2 works because you import only the parse function and refer to it without a module qualifier, since it is not imported in the context of the module. With this approach, you can only use an explicitly imported function from the parse module.
code 3 works because flask implicitly imports the urllib.parse module. The parse module becomes available in the context of the urllib module. After importing urllib urllib.parse becomes available and you can use it as in code 1
 source share