0

How can I create unicode entities out of python3 string objects?

Having smt _ 1 #, I want to generate smt%20_%201%20%23

pythad
  • 4,115
  • 2
  • 15
  • 40

1 Answers1

1

Use quote from urllib.parse:

>>> from urrlib.parse import quote
>>> quote('smt _ 1 #')
'smt%20_%201%20%23'

Since you aren't dealing with a url, you don't seem to need to specify any safe characters. If you'd also require / to be escaped, pass safe='' to quote.

Dimitris Fasarakis Hilliard
  • 136,212
  • 29
  • 242
  • 233