Unless /tmp/sudoku.html
already contains content, you need to close the file object first before calling wkhtmltopdf
to generate a PDF from it. Unless you flush
what you have already written to the file, nothing will be output to /tmp/sudoku.html
until you close the file. Try:
html = generate_html()
f = open("/tmp/sudoku.html", 'w+')
f.write(html)
f.close() # close the file first
system('wkhtmltopdf /tmp/sudoku.html sudoku.pdf')