2008-01-31
python 知识小结
关键字: python
转换字符集 为unicode字符集:unicode(shortname,“原字符集”,'ignore')
#得到文件的字符集
def detectCharset(file):
fileCharSet = "GBK"
detector = UniversalDetector()
for line in open(file):
detector.feed(line)
if detector.done: break
detector.close()
if detector.result.has_key("encoding"):
fileCharSet = detector.result["encoding"]
return str(fileCharSet)
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
得到系统的字符集
def getDefaultEncoding():
if hasattr(sys.stdin, 'encoding') and sys.stdin.encoding:
return sys.stdin.encoding
else :
import locale
locale_name, console_encoding = locale.getdefaultlocale()
return console_encoding
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
得到字符串的字符集
def chardetStr(s):
testlist=chardet.detect(s)
charset = testlist['encoding']
if charset=="GB2312":
charset="GBK"
return charset
python得到wav文件的播放时间
def getWAVDuration(filename):
import wave
w = wave.open(filename, "rb")
nf = w.getnframes()
w.close()
dur = math.ceil((nf*1.0)/44100)
return(int(dur))
#得到文件的字符集
def detectCharset(file):
fileCharSet = "GBK"
detector = UniversalDetector()
for line in open(file):
detector.feed(line)
if detector.done: break
detector.close()
if detector.result.has_key("encoding"):
fileCharSet = detector.result["encoding"]
return str(fileCharSet)
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
得到系统的字符集
def getDefaultEncoding():
if hasattr(sys.stdin, 'encoding') and sys.stdin.encoding:
return sys.stdin.encoding
else :
import locale
locale_name, console_encoding = locale.getdefaultlocale()
return console_encoding
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
得到字符串的字符集
def chardetStr(s):
testlist=chardet.detect(s)
charset = testlist['encoding']
if charset=="GB2312":
charset="GBK"
return charset
python得到wav文件的播放时间
def getWAVDuration(filename):
import wave
w = wave.open(filename, "rb")
nf = w.getnframes()
w.close()
dur = math.ceil((nf*1.0)/44100)
return(int(dur))
发表评论
- 浏览: 17174 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
DSC01762
共 1 张
共 1 张
最新评论
-
经常看《程序员》杂志的进 ...
我更爱看《非程序员》,可惜没得看了
-- by nighthawk -
经常看《程序员》杂志的进 ...
对于我这样的初学者感觉没什么用,很杂很没方向感。
-- by wangyifeng -
JSF中文教程
正好需要 感谢咯
-- by cainwise -
经常看《程序员》杂志的进 ...
蹲厕所的时候看
-- by 温柔一刀 -
经常看《程序员》杂志的进 ...
睡觉之前看一看
-- by javaboy2006






评论排行榜