Python: Importing urllib.quote

前端 未结 5 677
广开言路
广开言路 2021-01-30 00:22

I would like to use urllib.quote(). But python (python3) is not finding the module. Suppose, I have this line of code:

print(urllib.quote(\"châteu\"         


        
5条回答
  •  甜味超标
    2021-01-30 01:10

    If you need to handle both Python 2.x and 3.x you can catch the exception and load the alternative.

    try:
        from urllib import quote  # Python 2.X
    except ImportError:
        from urllib.parse import quote  # Python 3+
    

    You could also use the python compatibility wrapper six to handle this.

    from six.moves.urllib.parse import quote
    

提交回复
热议问题