Reputation: 1
Trying to write a string to a HTML file but am getting a syntax error on the third line 'pagetitle'. how can I properly export this? New to python and my notes aren't helping.
Writing in Python, exporting to HTML.
def paragraph_function(filename, pagetitle, textbody):
output_file = file(filename)
output_file.write('<html><head><title>'pagetitle'</title></head>')
Upvotes: 0
Views: 324
Reputation: 3373
Try this:
def paragraph_function(filename, pagetitle, textbody):
output_file = open(filename,'w+')
data = '<html><head><title>'+pagetitle+'</title></head>'
output_file.write(data)
pagetitle= 'page'
filename= 'out'
textbody = ''
paragraph_function(filename, pagetitle, textbody)
Upvotes: 0
Reputation: 7290
You should concatenate the pagetitle to the string being written to the output file
output_file.write('<html><head><title>' + pagetitle + '</title></head>')
Upvotes: 1