- 要么删除这些中文字串;
- 要么在文件首部插入编码行。
首先想到的是用UltraEdit的“在文件中替换”功能。可试了几次,老是无法匹配,换成E文并去掉"Unicode查找“选项就可以;中文则不行;要是用基本的查找功能倒可以匹配中文。真是不懂呀。应该是UE的Bug。--失败!
于是打开心爱的VIM,敲入下面的代码:
require ' find '
Find . find( ' /work/zilbo ' ) do | path |
unless File . directory ? (path) then
if [ " .py " ] . include ? File . extname(path) then
data = File . read (path)
unless (data . length == 0 ) then
name = File . basename(path)
File . delete (path)
File . open (path , " w " ) do | out |
out << " # -*- coding: utf-8 -*-/n "
out << data
end
end
end
end
end
经验证,一切如我所愿:
- 文件首插入了编码信息;
- 文件是以UTF-8保存的;
- 空文件(如__init__.py之类的)则跳过未处理。
2737




被折叠的 条评论
为什么被折叠?



