用with open(path,'rb')去读取文件夹中的文件,显示在该文件夹下找不到该文件,但是该文件是的的确确存在的。
因为用os.listdir()去读取该文件夹的时候是有该文件的
用with读取该文件:with open(r'//Users//chendingyu//Desktop//20220411//510880.dat','rb') as fo:
用os.listdir()读取文件夹:filepath = r'//Users//chendingyu//Desktop//20220411//'
path = os.listdir(filepath)
结果用with open就显示:No such file or directory: '510880.dat'
但是用os.listdir的结果中的确有这个dat文件。
不知道其中的缘由,初入编程的我请求各位的指导。

python读取文件夹内文件显示找不到的问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
8条回答 默认 最新
- bj_0163_bj 2022-04-26 10:36关注
##这样呢
with open('/Users/chendingyu/Desktop/20220411/510880.dat','rb') as fo: #读入
data=fo.read()本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用 1