[工程技巧]
2015-10-28 10:18
253 查看
#-*-coding:gbk-*-
2 #########################################################################
3 # Copyright (C) 2015 All rights reserved.
4 #
5 # 文件名称:getnltksinica.py
6 # 创 建 者:刘禹 finallyly liuyusi0121@sogou-inc.com(ext 3209)
7 # 创建日期:2015年10月28日
8 # 描 述:
9 #
10 # 备 注:
11 #
12 #########################################################################
13 #!/usr/bin/python
14 # please add your code here!
15 import sys
16 reload(sys)
17 sys.setdefaultencoding('utf8')
18 import nltk;
19 from nltk.corpus import sinica_treebank
20 sinica_fd=nltk.FreqDist(sinica_treebank.words())
21 print len(sinica_fd)
22 for m in sinica_fd:
23 sys.stdout.write("%s\n"%m);
有一份文档是UTF-8编码,直接打印到标准输出没有问题,但是重定向的话就会出错,因为系统的默认编码是GBK的。加上reload(sys)
sys.segdefaultencoding这两句就没错了。
2 #########################################################################
3 # Copyright (C) 2015 All rights reserved.
4 #
5 # 文件名称:getnltksinica.py
6 # 创 建 者:刘禹 finallyly liuyusi0121@sogou-inc.com(ext 3209)
7 # 创建日期:2015年10月28日
8 # 描 述:
9 #
10 # 备 注:
11 #
12 #########################################################################
13 #!/usr/bin/python
14 # please add your code here!
15 import sys
16 reload(sys)
17 sys.setdefaultencoding('utf8')
18 import nltk;
19 from nltk.corpus import sinica_treebank
20 sinica_fd=nltk.FreqDist(sinica_treebank.words())
21 print len(sinica_fd)
22 for m in sinica_fd:
23 sys.stdout.write("%s\n"%m);
有一份文档是UTF-8编码,直接打印到标准输出没有问题,但是重定向的话就会出错,因为系统的默认编码是GBK的。加上reload(sys)
sys.segdefaultencoding这两句就没错了。
相关文章推荐
- 从头认识java-4.9 枚举类型
- Android - RecycleView 使用 Universal-Image-Loader加载优化
- Jquery获取DropDownList的值
- c++多线程编程
- iOS 8 Auto Layout界面自动布局系列1-自动布局的基本原理
- iOS中UITextField 使用全面解析
- char*与wchar_t*(LPTSTR) 如何相互转换
- windbg调试入门
- com.bstek.dorado.data.variant.Record cannot be cast to
- 一些英语技巧
- ubuntu安装eclipse后菜单栏下拉失效
- SURF&SIFT
- android加载第三方字体的方法与效率
- 测试你的肝脏是否有毒素
- POJ 3259
- android:visibility
- 【转】到底EJB是什么
- Scrollbar实例
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- Unity3d 场景打包与加载