Reputation: 2121
Below, I print out the html
for a form defined externally. Is there a difference in the way each string is retrieved and used in foo.py
, other than the syntax? If so, in what circumstances would one method be preferred over the other? For example, would I be better off defining a number of html
files in a module as strings and access them that way, as opposed keeping them in separate .html files and using open
over and over?
mod.py
form = """\
<form type="POST" action="test.py">
Enter something:<input type="text" name="somethign">
</form>
"""
form.html
<form type="POST" action="test.py">
Enter something:<input type="text" name="something">
</form>
foo.py
import mod
print mod.form
with open('form.html', 'r') as form:
print form.read()
Upvotes: 0
Views: 121
Reputation: 137
Having .html files is better. Sure, you will have some overhead opening a file, reading its content and then closing it, but you'll have many advantages:
Upvotes: 1
Reputation: 799150
It's a lot easier for designers to edit discrete HTML files than to deal with HTML embedded in code.
Upvotes: 1