Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with html on python code

Tags:

python

html

php

so in PHP it's possible to have an entire section of php source be filled with direct raw html:

    <?php
    function doThis(){
    ?>

    <html>
    <a>LOOL</a>
    </html>


    <?php
    }

    doThis();

    ?>

and calling doThis() will print out all the html code between the curly braces...is there a similar functionality in Python? or do I have to virtually print all the HTML individually using the print command? python's indentation seems to make it really inconvenient to write HTML on python code

like image 656
kamikaze_pilot Avatar asked Dec 21 '22 14:12

kamikaze_pilot


1 Answers

I'm not certain I fully understand your question, but if you need to have long blocks of arbitrary text in Python the best way I've found is like so:

myHTML = """
<html>
<head>
<title>I am an HTML Page<title>
<head>
<body>
<div>Some content here.</div>
</body>
</html>
"""

The key is the triple Quotes. It allows you to put any other content between them, including line breaks, spacing, etc.

like image 112
g.d.d.c Avatar answered Jan 09 '23 16:01

g.d.d.c