Bev
Bev

Reputation: 1

Export string to HTML file

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

Answers (2)

Thiru
Thiru

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

Rami
Rami

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

Related Questions