码迷,mamicode.com
首页 > 其他好文 > 详细

关于jupyter notebook读写中文编码的问题

时间:2017-09-23 00:00:51      阅读:557      评论:0      收藏:0      [点我收藏+]

标签:readlines   bsp   highlight   3.x   pytho   python3   python3.x   not   notebook   

text = u" 在向你挥舞的各色花帕中,是谁的手突然收回,紧紧捂住了自己的眼睛,\n当人们四散离去,谁,还站在船尾,衣裙漫飞,如翻涌不息的云,江涛"
my_file = open(‘my file.txt‘,‘wb‘)
my_file.write(text.encode(‘utf-8‘))##
my_file.close()
append_text=u‘高一声低一声\n美丽的梦留下美丽的忧伤\n人间天上,代代相传\n但是,心\n真能变成石头吗\n为眺望远天的杳鹤\n错过无数次春江月明‘
my_file = open(‘my file.txt‘,‘ab‘)   #这里b是二进制,a是追加,这里不知道为什么一定要加上a才能够读入
my_file.write(append_text.encode(‘utf-8‘))
my_file.close()
file=open(‘my file.txt‘, encoding="utf-8")
content = file.read()
print(content)
file.close()
file=open(‘my file.txt‘, encoding="utf-8")
content = file.readlines()  #readline 第一次读第一行,第二次第二行
print(content)

  我用的python3.x

       总之各种百度了好多方法,有的适用而有的又不适用

       总之读文章的时候 encoding="utf-8"

       写入的时候text.encode(‘utf-8‘)这样

关于jupyter notebook读写中文编码的问题

标签:readlines   bsp   highlight   3.x   pytho   python3   python3.x   not   notebook   

原文地址:http://www.cnblogs.com/blairwaldorf/p/7577434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!