用python写入html文件时出现问题

2024-10-02 08:20:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难用python编写一个非常简单的html文件。你知道吗

代码是:

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()

这个文件看起来大约有65个字节,但是当我在chrome或firefox中打开它时,它是空白的。文件图标上有一个小锁,但当我右键单击选项时,权限包括我。所以…我不知道这是代码问题还是别的什么。另外,我桌面上的所有其他文件都有锁,我可以很好地打开它们。 我在这里寻求帮助(How to write and save html file in python?

我用的是Windows7,Python2.7Anaconda 谢谢。你知道吗


Tags: 文件代码messagehelloworldclose字节html
1条回答
网友
1楼 · 发布于 2024-10-02 08:20:42

你有一个额外的<,它把一切都搞砸了。你知道吗

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()

相关问题 更多 >

    热门问题