开发者

Python - print until marker (a la PHP)?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜