简单的Unicode字符串例子 uniFile.py
来源:互联网 发布:foxmail mac 编辑:程序博客网 时间:2024/05/21 11:07
这个简单的例子中,把一个Unicode字符串写入到磁盘文件,然后再把它读出并显示出来。写入和读出都用UTF-8编码
#/usr/bin/env python'''An example of reading and writing Unicode strings:Writesa Unicode string to a file in utf-8 and reads it back in.'''CODEC = 'utf-8'FILE = 'unicode.txt'hello_out = u"Hello world\n"bytes_out = hello_out.encode(CODEC)f = open(FILE,"w")f.write(bytes_out)f.close()f = open(FILE,"r")bytes_in = f.read()f.close()hello_in = bytes_in.decode(CODEC)print hello_in,
运行程序得到如下输出
$unicode_example.py
Hello World
创建一个叫unicode.txt的文件
$cat unicode.txt
Hello World!
0 0
- 简单的Unicode字符串例子 uniFile.py
- web.py服务端,jquery ajax简单例子
- py的简单计算
- Unicode 字符串的转换
- UniCode字符串的拷贝
- py匹配字符串中间的字符串
- py字符串
- 一个简单的读取json字符串的小例子
- 字符串作为freemarker模板的简单实现例子
- java 字符串作为freemarker模板的简单实现例子
- 字符串作为freemarker模板的简单实现例子
- php分割中文字符串为数组的简单例子
- 字符串作为freemarker模板的简单实现例子
- [py]py字符编码unicode utf8 ascii
- python字符串专题 以及Unicode应用小例子
- 获取字符串的unicode编码
- 举个Unicode 编程的例子
- js 将汉字转化成unicode 16 编码 简单例子
- 中点Bresenham算法光栅化画直线(个人总结精简版)代码超短!速度极快!
- redhat enterprise 7.0更改启动方式
- java调用shell命令并获取执行结果
- boost::asio::Io_service strand
- Mutex::AutoLock介绍
- 简单的Unicode字符串例子 uniFile.py
- Libev事件库源码阅读笔记
- 铜川试点 ,前台ajax内部异常问题,所延伸出来的补习HTTP状态码,做个对于自己的记录
- O(1)时间求一个栈的最小值
- 误差扩散原理
- 使用stringstream 来进行string和其他类型的转换
- PHP Notice: Undefined index: ... 问题的解决方法:
- 系统状态栏显隐的控制
- eclipse鼠标变成十字架