Home > OS >  Is there a way to encase a text which contains lots of operators/formatting and ignore all interpret
Is there a way to encase a text which contains lots of operators/formatting and ignore all interpret

Time:05-02

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.

CodePudding user response:

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.

CodePudding user response:

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"/>"""

CodePudding user response:

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"/>'
  • Related