看板Python
标 题Re: [问题] 如何让输入的字串以Big5表示?
发信站老鼠的香香乳酪洞 (Thu Jul 24 22:52:57 2008)
转信站ptt!ctu-reader!ctu-peer!news.nctu!csnews.cs.nctu!news.cs.nctu!Mouse
※ 引述《[email protected] (那是啥)》之铭言:
: ※ 引述《yungyuc (酷狗喵千代)》之铭言:
: : check http://www.diveintopython.org/xml_processing/unicode.html
: 谢谢您提供的资料
: Dive into Python我有拜读过了~不过这边的unicode资料似乎没什麽帮助
: : BTW, 你的程式有错;lines 不像你所想的是 list,它变成 str 了
: : 这样才对:
: : f = open("foo", 'r')
: : a = str(raw_input("word: "))
: : for line in f:
: : print line if line.find(a) >= 0
: 後来我将程式改成这样
: f = open("txtdb.txt", 'r')
: #因为windows下预设以Big5输入,所以我将输入的值转成utf8
: a = str(raw_input("word: ")).decode('Big5').encode('utf8')
: for line in f:
line=line.decode('utf8')
: if line.find(a) >= 0:
: print line
: return 0
: 并把档案改编为utf-8,
: 不过还是连一行资料都找不到,不知道问题到底在哪...
: 感谢您的回答:)
: 喔对了 我是在windows平台下 使用eclipse + pydev开发的
: python为v 2.5
: 不过在尝试写这行
: print line if line.find(a) >= 0
: 的时候会有错,好像一定要拆开来。所以我就拆开来写了。
--
※Post by zao from solver.csie.ntu.edu.tw
老鼠的香香乳酪洞˙电子布告栏系统˙alexbbs.twbbs.org˙140.113.166.7