how I can to replace space char in '%20'

11 views
Skip to first unread message

נתי שטרן

unread,
Nov 23, 2020, 1:23:47 PM11/23/20
to desertpy
I tried this `in this code:


query3=""
for u in quer2y.split(' ')
query3=query3+"%20"+u

Andy Vaught

unread,
Nov 23, 2020, 3:09:44 PM11/23/20
to dese...@googlegroups.com

   How about:

       query3 = query2.replace(' ', '%20')



--
You received this message because you are subscribed to the Google Groups "desertpy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to desertpy+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/desertpy/135a17ad-c5a2-42cd-8910-c4ce9d74f9can%40googlegroups.com.

Randy K

unread,
Nov 23, 2020, 9:07:18 PM11/23/20
to desertpy
How about using urllib.parse.quote instead of trying to roll your own, and also get other % subsitutions, too? Unless of course you want to ignore those.

>>> urllib.parse.quote("here's some delimited stuff")
'here%27s%20some%20delimited%20stuff'

Randy K

unread,
Nov 23, 2020, 9:08:16 PM11/23/20
to desertpy
I left off the "import urllib.parse" so don't forget that. :D 

נתי שטרן

unread,
Nov 24, 2020, 4:02:26 AM11/24/20
to desertpy
it doesnt work

ב-יום שלישי, 24 בנובמבר 2020 בשעה 04:08:16 UTC+2, Randy K כתב/ה:

Randy K

unread,
Nov 24, 2020, 5:00:55 PM11/24/20
to desertpy
Are you using python 2 or 3?

Should work in all reasonably recent versions of 3.
In python 2, it's urllib.quote(), and you just import urllib instead.

Reply all
Reply to author
Forward
0 new messages