【python】'utf8' codec can't decode byte 0xb6

来源:互联网 发布:淘宝免费申请试用几次 编辑:程序博客网 时间:2024/05/22 18:55



#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 打开一个文件
fo = open("1.txt", "r+")
str = fo.read(10);
print ("读取的字符串是 : ", str)
 
# 查找当前位置
position = fo.tell();
print ("当前文件位置 : ", position)
 
# 把指针再次重新定位到文件开头
position = fo.seek(2, 0);
str = fo.read(100);
print ("重新读取字符串 : ", str)
# 关闭打开的文件
fo.close()


#############################

特别注意下,这里打开的文件格式要是utf-8,因为nodepad++格式是ANSI,所以要在nodepad++里将文件另存为utf-8格式

0 0
原创粉丝点击