Python: Importing urllib.quote

前端 未结 5 676
广开言路
广开言路 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 00:59

    In Python 3.x, you need to import urllib.parse.quote:

    >>> import urllib.parse
    >>> urllib.parse.quote("châteu", safe='')
    'ch%C3%A2teu'
    

    According to Python 2.x urllib module documentation:

    NOTE

    The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.

提交回复
热议问题