相关疑难解决方法(0)

无法从python中的目录打开文件

我写了一个小模块,它首先找到目录中的所有文件,然后合并它们。但是,我在从目录中打开这些文件时遇到了问题。我确保我的文件和目录名称是正确的,并且文件实际上在目录中。

下面是代码..

 seqdir = "results"
 outfile = "test.txt"

 for filename in os.listdir(seqdir):
     in_file = open(filename,'r') 
Run Code Online (Sandbox Code Playgroud)

下面是错误..

     in_file = open(filename,'r')     
     IOError: [Errno 2] No such file or directory: 'hen1-1-rep1.txt'
Run Code Online (Sandbox Code Playgroud)

python ioerror

4
推荐指数
1
解决办法
1463
查看次数

区分文件和目录

所以我确定这是一个愚蠢的问题,但我查看了Python的文档并尝试了几个Google代码,但没有一个有效.

似乎以下应该工作,但它返回"False"为我的目录/ foo/bar我有3项:1文件夹"[文件夹]",1文件"测试"(没有扩展名),和1文件"测试py"为.

我希望有一个脚本可以区分文件夹和一堆函数的文件,但我无法找出任何有用的东西.

#!/usr/bin/python
import os, re
for f in os.listdir('/foo/bar'):
    print f, os.path.isdir(f)
Run Code Online (Sandbox Code Playgroud)

目前为所有内容返回false.

python

3
推荐指数
1
解决办法
1413
查看次数

标签 统计

python ×2

ioerror ×1