1

I'm having trouble writing a very simple html file in python.

The code is:

filehtml = 'C:\pathhere\helloworld.html'

message = '''<html>
<head></head>
<body><p><Hello World!</p></body>
</html>'''

f = open(filehtml,'w')
f.write(message)
f.close()

The file appears, is about 65 bytes, but when I open it in chrome or firefox it's blank. There's a little lock on the file icon, but when I right click on options, the permissions include me. So...I don't know if this is a code problem or something else. Also, all the other files on my desktop have locks and I open them just fine. I looked here for help (How to write and save html file in python?)

I'm using Windows 7, python 2.7 Anaconda Thanks.

4
  • Open the file in notepad to see if it is writing properly Commented Aug 12, 2016 at 17:53
  • Btw, you should use the with-syntax Commented Aug 12, 2016 at 17:57
  • Flagged to close because this is a find my typo question Commented Aug 12, 2016 at 17:59
  • I see now, sorry! I read over it waaaayy to many times, all before coffee. Commented Aug 12, 2016 at 18:41

1 Answer 1

2

You have an extra < which is messing everything up.

filehtml = 'C:\pathhere\helloworld.html'

message = '''<html>
<head></head>
<body><p>Hello World!</p></body>
</html>'''

f = open(filehtml,'w')
f.write(message)
f.close()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.