Python: Importing urllib.quote

前端 未结 5 574
广开言路
广开言路 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:21

    This is how I handle this, without using exceptions.

    import sys
    if sys.version_info.major > 2:  # Python 3 or later
        from urllib.parse import quote
    else:  # Python 2
        from urllib import quote
    

提交回复
热议问题