+ 4
print statement working wrong in python
Recently I wrote a code in python in that code the program output is showing wrong in the output . In line 9 and line 10 there is a print statement in triple quotes please see the line 10 there is an U.R.L https://news.google.com/covid19/maphl=enIN&mid=/m/02j71&gl=IN&ceid=IN:en and the see the second line in the output of the code it is showing like that https:/../Playground/?hl=en-IN&mid=/m/02j71&gl=IN&ceid=IN:en can somebody explain why this is happening. The code is https://code.sololearn.com/cPZYk71JGHQb/#py
4 odpowiedzi
+ 1
https://code.sololearn.com/cKz7qiiYzNQR/?ref=app
https://code.sololearn.com/cQ10b5NZVrcK/?ref=app
Well, it is not only in python. I think there might be a regex expression somewhere between the result of the code and the sending of the result of the code... I don't know what it is, that's really strange...
+ 1
Well, it seems that it doesn't change the output but it modifies directly the input file and seems to replace all '/a/b/c/d' by '../Playground/'. That is really strange 🤔
And it doesn't only replace text in strings but also in the whole file. Look again at my python code.
+ 1
I can't figure it out how to stop server modifying the URL, as well.
A simple solution is remove the protocol of the URL, and keep the domain name, path and query string.
Example:
https://news.google.com/covid19/maphl=enIN&mid=/m/02j71&gl=IN&ceid=IN:en
> news.google.com/covid19/maphl=enIN&mid=/m/02j71&gl=IN&ceid=IN:en
Without the protocol, browsers (Chrome, FireFox, ...) can still find the destination!
0
There is another solution, actually. In fact, I looked again, and the output of the code is modified, not the input file.
The easiest way is to decorate the print function in order to have :
"https://an/url/here" => chr(0).join("https://an/url/here")
By placing a null char between each char of the string, it does not impact the render of the output and it prevents from matching a pattern like '/a/b/c' since it is now '/\x00a\x00/\x00b\x00/\x00c'