Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“我该如何解决?”;FileNotFoundError:[Errno 2]没有这样的文件或目录:";在使用Visual Studio代码时使用Python?_Python_Visual Studio - Fatal编程技术网

“我该如何解决?”;FileNotFoundError:[Errno 2]没有这样的文件或目录:";在使用Visual Studio代码时使用Python?

“我该如何解决?”;FileNotFoundError:[Errno 2]没有这样的文件或目录:";在使用Visual Studio代码时使用Python?,python,visual-studio,Python,Visual Studio,我刚刚开始学习Python,我看了这个视频教程- 当我试图使用视频中的方法创建自己的.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 para

我刚刚开始学习Python,我看了这个视频教程-

当我试图使用视频中的方法创建自己的.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)
但它没有起作用,任何建议都将不胜感激


liam

无论何时需要调试,您都需要更改文件的路径以在调试模式下打开它,只需执行以下操作:

  • 去探险家
  • 在文件上单击鼠标右键,然后单击“复制相对路径”
  • 把那条路打开
  • 我还看到您在代码中添加了以下内容:

    my_html_file = open("C:\Users\Liam\Documents\Coding\My Files\Python\My Tests/my_html_file.html" "w")
    
    你在w之前错过了昏迷,应该是这样的:

    my_html_file = open("C:\Users\Liam\Documents\Coding\My Files\Python\My Tests/my_html_file.html","w")
    

    编辑:哈哈,现在我看到其他人通过回答回答你的问题,无论如何,这也应该有助于其他人!至少…

    每当需要调试时,您需要更改文件的路径以在调试模式下打开它,只需执行以下操作:

  • 去探险家
  • 在文件上单击鼠标右键,然后单击“复制相对路径”
  • 把那条路打开
  • 我还看到您在代码中添加了以下内容:

    my_html_file = open("C:\Users\Liam\Documents\Coding\My Files\Python\My Tests/my_html_file.html" "w")
    
    你在w之前错过了昏迷,应该是这样的:

    my_html_file = open("C:\Users\Liam\Documents\Coding\My Files\Python\My Tests/my_html_file.html","w")
    

    编辑:哈哈,现在我看到其他人通过回答回答你的问题,无论如何,这也应该有助于其他人!至少…

    这样做的原因是文件名和打开文件的模式之间缺少一个逗号。因此,解释器试图读取文件,如果您请求的文件不存在,将导致错误。

    原因是文件名和打开文件的模式之间缺少逗号。因此,解释器试图读取该文件,如果您请求的文件不存在,则会导致错误。

    目录是否存在?参数之间需要逗号,否则Python会连接字符串。将
    ,“w”)
    而不仅仅是
    “w”)
    。它将查找
    .htmlw
    文件,并尝试以“读取”模式打开它。亲爱的Peter,谢谢,这就是问题所在,我不敢相信我错过了它。目录是否存在?参数之间需要逗号,否则Python会连接字符串。将
    ,“w”)
    而不仅仅是
    “w”)
    。它将查找
    .htmlw
    文件,并尝试以“读取”模式打开它。亲爱的Peter,谢谢,这就是问题所在,我不敢相信我错过了它。