zoukankan      html  css  js  c++  java
  • Python中的打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:(转载)

    下面的问题是我在学习Python打开文件的时候遇到的一个问题,如果刚好对应了你的问题,那是最好,如果不适合,起码可以帮助排除一种可能吧。

    原程序:

    报错:FileNotFoundError: [Errno 2] No such file or directory: hamlet.txt

    原程序:

     

    说明一下,这里引号前面加一个字母 r 是为了确保在Windows系统中万无一失,故应该以原始字符串的方式指定路径,也就是在开头的引号前面加上 r 。

    报错:FileNotFoundError: [Errno 2] No such file or directory: 'E:\Python Programs\Self-written programs\hamlet.txt'

    解决办法:把对应的文件的后缀名去掉!比如:原来你文件夹里的文件名是hamlet.txt,应该把它改为hamlet,也就是不用管后缀的事,因为后缀是自带的。

    注:
    (1).第一个截图的情况:python程序和要打开的文件在同一个文件夹下。

    (2).第二个截图的情况:采用绝对路径的方法来打开文件。

    (3).在Linux或者OS X中,使用绝对路径打开文件的时候应该使用斜杠/,在Windows中的时候,应该使用反斜杠。


    原文链接:https://blog.csdn.net/abcde520906/article/details/91397720

  • 相关阅读:
    hdu5728 PowMod
    CF1156E Special Segments of Permutation
    CF1182E Product Oriented Recurrence
    CF1082E Increasing Frequency
    CF623B Array GCD
    CF1168B Good Triple
    CF1175E Minimal Segment Cover
    php 正则
    windows 下安装composer
    windows apache "The requested operation has failed" 启动失败
  • 原文地址:https://www.cnblogs.com/yiyaxuan/p/13360393.html
Copyright © 2011-2022 走看看