• <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] 没有这样的文件或目录

        FileNotFoundError: [Errno 2] No such file or directory(FileNotFoundError: [Errno 2] 没有这样的文件或目录)
        <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] 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

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

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