【发布时间】:2020-11-08 22:47:21
【问题描述】:
我刚刚开始学习 Python,我观看了这个视频教程 - https://www.youtube.com/watch?v=rioXu6EBN0s
当我尝试使用视频中的方法创建自己的 .hmtl 文件时,出现此错误 -
FileNotFoundError: [Errno 2] No such file or directory:
这是我在 Visual Studio 中输入的——
my_variable = "<html><body><p>This is a paragraph.</p><p>This is another paragraph.</p></body></html>"
my_html_file = open("C:\Users\Liam\Documents\Coding\My Files\Python\My Tests/my_html_file.html" "w")
my_html_file.write(my_variable)
我试过改成
/Users/Liam.Documents/Coding/My Files/Python/My Tests/
/my_html_file.html
但它没有奏效,任何建议将不胜感激。
利亚姆
【问题讨论】:
-
目录是否存在?
-
参数之间需要逗号,否则 Python 会连接字符串。输入
, "w")而不仅仅是"w")。它将寻找.htmlw文件并尝试以“读取”模式打开它。 -
亲爱的彼得,谢谢你,这就是问题所在,我不敢相信我错过了。
标签: python visual-studio