'Is there a way to encase a text which contains lots of operators/formatting and ignore all interpretation?
So for example:
txt = r"<img alt="image tags" height="652" id="image" onclick="Note.toggle();" src="https://us.example.com//images/1/5d2.gif?1" width="600"/>"
Now, clearly, this doesn't work for a lot of reasons, namely quotations and escape characters. It's possible to manually format each txt but this is intended to automatically find img from webpages.
I think Regex might be a clear solution here but if there is just some character to place before and after then that would be ideal. I'm a lot more used to C++ where this would have been trivial, I apologize for my lack of experience.
Solution 1:[1]
I believe using triple quotes will solve the problem you are facing:
txt = r"""<img alt="image tags" height="652" id="image" onclick="Note.toggle();" src="https://us.example.com//images/1/5d2.gif?1" width="600"/>"""
Triple quotes allow you to have strings spanning multiple lines and also avoid difficulties in using single or double quotes in the string. The r prefix escapes any special characters (e.g., backslash) in the string.
Solution 2:[2]
I think what you are searching for is r"""..."""
txt = r"""<img alt="image tags" height="652" id="image" onclick="Note.toggle();" src="https://us.example.com//images/1/5d2.gif?1" width="600"/>"""
Solution 3:[3]
In this case you could simply use single quotation marks.
txt = r'<img alt="image tags" height="652" id="image" onclick="Note.toggle();" src="https://us.example.com//images/1/5d2.gif?1" width="600"/>'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user-124812948 |
| Solution 2 | Rabinzel |
| Solution 3 | Klaus |
