• <i id='Odfoe'><tr id='Odfoe'><dt id='Odfoe'><q id='Odfoe'><span id='Odfoe'><b id='Odfoe'><form id='Odfoe'><ins id='Odfoe'></ins><ul id='Odfoe'></ul><sub id='Odfoe'></sub></form><legend id='Odfoe'></legend><bdo id='Odfoe'><pre id='Odfoe'><center id='Odfoe'></center></pre></bdo></b><th id='Odfoe'></th></span></q></dt></tr></i><div id='Odfoe'><tfoot id='Odfoe'></tfoot><dl id='Odfoe'><fieldset id='Odfoe'></fieldset></dl></div>
  • <tfoot id='Odfoe'></tfoot>
      <bdo id='Odfoe'></bdo><ul id='Odfoe'></ul>

    <legend id='Odfoe'><style id='Odfoe'><dir id='Odfoe'><q id='Odfoe'></q></dir></style></legend>

    <small id='Odfoe'></small><noframes id='Odfoe'>

      1. FileNotFoundError: [Errno 2] 没有这样的文件或目录

        时间:2023-08-30
        <legend id='V2fCo'><style id='V2fCo'><dir id='V2fCo'><q id='V2fCo'></q></dir></style></legend>
        <i id='V2fCo'><tr id='V2fCo'><dt id='V2fCo'><q id='V2fCo'><span id='V2fCo'><b id='V2fCo'><form id='V2fCo'><ins id='V2fCo'></ins><ul id='V2fCo'></ul><sub id='V2fCo'></sub></form><legend id='V2fCo'></legend><bdo id='V2fCo'><pre id='V2fCo'><center id='V2fCo'></center></pre></bdo></b><th id='V2fCo'></th></span></q></dt></tr></i><div id='V2fCo'><tfoot id='V2fCo'></tfoot><dl id='V2fCo'><fieldset id='V2fCo'></fieldset></dl></div>
        <tfoot id='V2fCo'></tfoot>
          <tbody id='V2fCo'></tbody>

                • <bdo id='V2fCo'></bdo><ul id='V2fCo'></ul>

                  <small id='V2fCo'></small><noframes id='V2fCo'>

                • 本文介绍了FileNotFoundError: [Errno 2] 没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试打开一个 CSV 文件,但由于某种原因 python 无法找到它.

                  I am trying to open a CSV file but for some reason python cannot locate it.

                  这是我的代码(这只是一个简单的代码,但我无法解决问题):

                  Here is my code (it's just a simple code but I cannot solve the problem):

                  import csv
                  
                  with open('address.csv','r') as f:
                      reader = csv.reader(f)
                      for row in reader:
                          print row
                  

                  推荐答案

                  当你打开一个名为 address.csv 的文件时,你是在告诉 open()您的文件在当前工作目录中的功能.这称为相对路径.

                  When you open a file with the name address.csv, you are telling the open() function that your file is in the current working directory. This is called a relative path.

                  为了让您了解这意味着什么,请将其添加到您的代码中:

                  To give you an idea of what that means, add this to your code:

                  import os
                  
                  cwd = os.getcwd()  # Get the current working directory (cwd)
                  files = os.listdir(cwd)  # Get all the files in that directory
                  print("Files in %r: %s" % (cwd, files))
                  

                  这将打印当前工作目录以及其中的所有文件.

                  That will print the current working directory along with all the files in it.

                  告诉 open() 函数的另一种方法是使用绝对路径,例如:

                  Another way to tell the open() function where your file is located is by using an absolute path, e.g.:

                  f = open("/Users/foo/address.csv")
                  

                  这篇关于FileNotFoundError: [Errno 2] 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PDFMiner (Python) 处理在线 pdf 文件.编码网址? 下一篇:Numpy:快速找到第一个价值索引

                  相关文章

                  <tfoot id='MoyZT'></tfoot>

                    <small id='MoyZT'></small><noframes id='MoyZT'>

                    <i id='MoyZT'><tr id='MoyZT'><dt id='MoyZT'><q id='MoyZT'><span id='MoyZT'><b id='MoyZT'><form id='MoyZT'><ins id='MoyZT'></ins><ul id='MoyZT'></ul><sub id='MoyZT'></sub></form><legend id='MoyZT'></legend><bdo id='MoyZT'><pre id='MoyZT'><center id='MoyZT'></center></pre></bdo></b><th id='MoyZT'></th></span></q></dt></tr></i><div id='MoyZT'><tfoot id='MoyZT'></tfoot><dl id='MoyZT'><fieldset id='MoyZT'></fieldset></dl></div>
                  1. <legend id='MoyZT'><style id='MoyZT'><dir id='MoyZT'><q id='MoyZT'></q></dir></style></legend>

                      • <bdo id='MoyZT'></bdo><ul id='MoyZT'></ul>