开发者

Python - print until marker (a la PHP)?

开发者 https://www.devze.com 2023-01-23 05:53 出处:网络
In PHP I can do this: print <<<END This uses the \"here开发者_StackOverflow社区 document\" syntax to output

In PHP I can do this:

print <<<END
This uses the "here开发者_StackOverflow社区 document" syntax to output
multiple lines
END;

Is there a way to do something similar in Python?

I want to dump a big chunk of HTML without worrying about escaping e.g. angle brackets.


Python doesn't have heredocs with arbitrary start/end markers. You can use triple quotes (either single or double) to achieve something very similar:

print '''
This uses the "here document" syntax to output
multiple lines
'''

Add an r to make it a raw string so that backslash is also not treated specially. r'''....'''

0

精彩评论

暂无评论...
验证码 换一张
取 消