刚才在调试一个Django的应用
Zilbo,好不容易将配置弄齐了,到执行
manage.py syncdb时报错,说文件的编码设置不正确。打开一看,原来是SVN客户端在Check Out该项目时自动插入了本地(中文)时间戳,像“...(星期五,5 十一月)...”之类的东东。真是讨厌。想继续的话,就只能:
首先想到的是用UltraEdit的“在文件中替换”功能。可试了几次,老是无法匹配,换成E文并去掉"Unicode查找“选项就可以;中文则不行;要是用基本的查找功能倒可以匹配中文。真是不懂呀。应该是UE的Bug。--失败!
于是打开心爱的VIM,敲入下面的代码:
经验证,一切如我所愿:
- 要么删除这些中文字串;
- 要么在文件首部插入编码行。
首先想到的是用UltraEdit的“在文件中替换”功能。可试了几次,老是无法匹配,换成E文并去掉"Unicode查找“选项就可以;中文则不行;要是用基本的查找功能倒可以匹配中文。真是不懂呀。应该是UE的Bug。--失败!
于是打开心爱的VIM,敲入下面的代码:
#
!/usr/bin/ruby -Ku
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
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之类的)则跳过未处理。