2
I wanted to understand the difference between utils::URLencode()
in the R and the urllib.parse.quote()
in Python, for example:
In R:
tster <- '{"yearStart":"2020",\n"yearEnd":"2020",\n"typeForm":1}'
utils::URLencode(tster)
Output:
'%7B%22yearStart%22:%222020%22,%0A%22yearEnd%22:%222020%22,%0A%22typeForm%22:1%7D'
Python:
import urllib
tster = '{"yearStart":"2020",\n"yearEnd":"2020",\n"typeForm":1}'
result_py = urllib.parse.quote(tster, encoding = 'utf-8')
result_py
Output:
'%7B%22yearStart%22%3A%222020%22%2C%0A%22yearEnd%22%3A%222020%22%2C%0A%22typeForm%22%3A1%7D'
The difference in this case can be solved with, which leaves the output in Python equal to that of R:
result_py.replace('%3A',':').replace('%2C',',')
Output:
'%7B%22yearStart%22:%222020%22,%0A%22yearEnd%22:%222020%22,%0A%22typeForm%22:1%7D'
But for larger strings, ugly is very laborious. How to get Python output equal to R?
I left the two codes for comparison in the links:
In R: https://colab.research.google.com/drive/1oj-GCCUX4MZB_jW942DBMny-kN1sXdvy?usp=sharing
Python: https://colab.research.google.com/drive/1jpo9GrcTrFNidIdQih3PkLMR88t690kZ?usp=sharing