小编gmo*_*evt的帖子

os.path.isfile无法按预期工作

我正在尝试扫描我的硬盘以获取jpg和mp3文件.

我编写了以下脚本,如果我在根目录中传递一个带有文件的目录但是如果我将它传递给根目录则不会返回任何内容.

我是Python的新手,所以会喜欢一些帮助.

def findfiles(dirname,fileFilter):

    filesBySize = {}

    def filterfiles(f):
        ext = os.path.splitext(f)[1][1:]
        if ext in fileFilter:
            return True
        else:
            False

    for (path, dirs, fnames) in os.walk(dirname):
        if len(fileFilter)>0:
            fnames = filter(filterfiles,fnames)

        d = os.getcwd()
        os.chdir(dirname)      
        for f in fnames:
            if not os.path.isfile(f) :
                continue

            size = os.stat(f)[stat.ST_SIZE]
            if size < 100:
                continue
            if filesBySize.has_key(size):
                a = filesBySize[size]
            else:
                a = []
                filesBySize[size] = a
            a.append(os.path.join(dirname, f))
          #  print 'File Added: %s' %os.path.join(dirname,f)
            _filecount = _filecount + 1
        os.chdir(d)

    return …
Run Code Online (Sandbox Code Playgroud)

python

8
推荐指数
1
解决办法
2万
查看次数

使用Python解析BibText引文格式

在python中解析这个结果的最佳方法是什么?我试过正则表达式,但无法让它工作.我正在寻找标题词,作者等作为键.

@article{perry2000epidemiological,
  title={An epidemiological study to establish the prevalence of urinary symptoms and felt need in the community: the Leicestershire MRC Incontinence Study},
  author={Perry, Sarah and Shaw, Christine and Assassa, Philip and Dallosso, Helen and Williams, Kate and Brittain, Katherine R and Mensah, Fiona and Smith, Nigel and Clarke, Michael and Jagger, Carol and others},
  journal={Journal of public health},
  volume={22},
  number={3},
  pages={427--434},
  year={2000},
  publisher={Oxford University Press}
}
Run Code Online (Sandbox Code Playgroud)

python regex bibtex

1
推荐指数
2
解决办法
681
查看次数

标签 统计

python ×2

bibtex ×1

regex ×1