5

What I want to do is:

I have a directory name and file name. I want to add them to a URL and make a URL call. Lets say the directory is

D:/somedir/userdata/scripts

and the file name is myscript.txt

I want to add these as parameters to URL call but I want to encode them separately and not as key value pair. What I want is a function which can take input like:

D:/somedir/userdata/scripts

and return output like:

D%3A%2Fsomedir%2Fuserdata%2Fscripts

1 Answer 1

5

In Python 3:

>>> import urllib.parse
>>> urllib.parse.quote_plus('D:/somedir/userdata/scripts')
'D%3A%2Fsomedir%2Fuserdata%2Fscripts'

In Python 2:

>>> import urllib
>>> urllib.quote_plus('D:/somedir/userdata/scripts')
'D%3A%2Fsomedir%2Fuserdata%2Fscripts'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.