从os.walk中排除二进制文件 [英] exclude binary files from os.walk

查看:69
本文介绍了从os.walk中排除二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以排除二进制文件(我正在使用Windows XP)

来自os.walk()返回的文件列表?


另外,在阅读文件时你不确定它们是否是bb b或二进制文件,我一直认为它对''rb''更安全阅读,这是正确的......这是正确的...如果是这样,这背后的原因是什么?再次,所有

属于Windows XP和Python 2.4上的文件


非常感谢!

Is there an easy way to exclude binary files (I''m working on Windows XP)
from the file list returned by os.walk()?

Also, when reading files and you''re unsure as to whether or not they are
ascii or binary, I''ve always thought it safer to ''rb'' on the read, is
this correct... and if so, what''s the reasoning behind this? Again all
of this pertains to files on Windows XP and Python 2.4

Many thanks!

推荐答案

2005-01-26,rbt< rb*@athop1.ath.vt.edu>写道:
On 2005-01-26, rbt <rb*@athop1.ath.vt.edu> wrote:
有没有一种简单的方法可以从os.walk()返回的文件列表中排除二进制文件(我正在使用Windows XP)?


当然,假设您可以提供二进制

文件的严格定义。 :)

此外,在阅读文件时,你不确定是否或不是ascii或二进制文件,我一直认为它更安全
'阅读'rb'',这是正确的...


这取决于你想要什么。添加''b''将禁用

cr / lf处理。不知道它还做了什么。

如果是这样,这背后的原因是什么?


背后是什么?

所有这些都与Windows XP和Python 2.4上的文件有关
Is there an easy way to exclude binary files (I''m working on
Windows XP) from the file list returned by os.walk()?
Sure, assuming you can provide a rigorous definition of ''binary
files''. :)
Also, when reading files and you''re unsure as to whether or
not they are ascii or binary, I''ve always thought it safer to
''rb'' on the read, is this correct...
That depends on what you want. Adding a ''b'' will disable the
cr/lf handling. Not sure what else it does.
and if so, what''s the reasoning behind this?
Behind what?
Again all of this pertains to files on Windows XP and Python 2.4




-

格兰特爱德华兹格兰特哇!现在我在APPLE上有我的

,我理解COST

visi.com会计!!



--
Grant Edwards grante Yow! Now that I have my
at "APPLE", I comprehend COST
visi.com ACCOUNTING!!


Grant Edwards写道:
Grant Edwards wrote:
2005-01-26,rbt< rb*@athop1.ath.vt.edu>写道:

On 2005-01-26, rbt <rb*@athop1.ath.vt.edu> wrote:

有没有一种简单的方法可以从os.walk返回的文件列表中排除二进制文件(我正在使用Windows XP) ()?
Is there an easy way to exclude binary files (I''m working on
Windows XP) from the file list returned by os.walk()?



当然,假设您可以提供严格的二进制文件定义。 :)


Sure, assuming you can provide a rigorous definition of ''binary
files''. :)




non-ascii



non-ascii


没有明确的方式告诉文件是

" non-ascii"。二进制文件中的字节定义

非常好的ascii字符。 Windows

取决于文件扩展名以尝试跟踪

的类型文件中的数据,但这不是万无一失的。我可以用

a .EXE扩展名重命名一个普通的ascii文件。


我们可以提供更多帮助,如果你需要

时间来解释一下你在尝试什么

要做什么。


拉里贝茨


rbt写道:
There''s no definitive way of telling a file is
"non-ascii". Bytes in a binary file define
perfectly good ascii characters. Windows
depends on file extensions to try to keep track
of the "type" of data in a file, but that isn''t
foolproof. I can rename a plain ascii file with
a .EXE extension.

We could be of more help, if you would take the
time to explain a little about what you are trying
to do.

Larry Bates

rbt wrote:
Grant Edwards写道:
Grant Edwards wrote:
2005-01-26,rbt< rb*@athop1.ath.vt.edu>写道:

On 2005-01-26, rbt <rb*@athop1.ath.vt.edu> wrote:

有没有一种简单的方法可以从os.walk返回的文件列表中排除二进制文件(我正在使用Windows XP) ()?
Is there an easy way to exclude binary files (I''m working on
Windows XP) from the file list returned by os.walk()?



当然,假设您可以提供严格的二进制文件定义。 :)



Sure, assuming you can provide a rigorous definition of ''binary
files''. :)



non-ascii


non-ascii



这篇关于从os.walk中排除二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆