|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 dodopromi 于 2016-10-3 09:59 编辑
python的文件, 竟然自己能写一点用的着的挺开心. 不过步步是坑. 从语法, 到思路..
现在就是, 我要扫描一个文件中的gre单词, 并把他们打出来. 目前,我不知道怎么做
- f = open(r'C:\Documents and Settings\Administrator\桌面\学习\test\2.txt','r')
- f1=open(r'C:\Documents and Settings\Administrator\桌面\学习\test\new3.txt','w')
- gre=open(r'C:\Documents and Settings\Administrator\桌面\学习\test\gre.txt','r')
- gredic={}
- for each_line in gre:
- gredic[each_line.split('\t\t')[0]]=each_line.split('\t\t')[-1]
- print(gredic)
-
- for each_line in f:
- words=each_line.split()
-
- for each_word in words:
- if each_word in gredic:
- print(each_word,'是gre词汇')
-
- f.close
- f1.close
- gre.close
复制代码
错误信息提示
Traceback (most recent call last):
File "C:/Python34/插入词典.py", line 4, in <module>
gredic=gre.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 9626: illegal multibyte sequence
关于编码问题,我倒腾好几次了,反反复复的把各个文件存成各种格式的,都没用
问题:
1 这个in position 9626是个什么东西, 为什么随着文件的变化, 一直在变化
2, 如果是个特殊的符号, 我能不能一次找到全部删掉,但是文本下面我看不到啊.
3, 而且file.seek(), 和file.tell() 时好时坏
字典gre长这个模样
abacus n.算盘
abandon v.n.放弃,放纵
abase v.贬抑,使卑下
abate v.减轻,降低
abattoir n.屠宰场,角斗场
问题
我这种方式是不是会占据很大内存,让电脑执行的很慢, 正常思路是怎样的, 是应该建立数据库吗? 或是python还有其他的解决方案
好吧,我没说清楚,重新说.
现在我有一个gre.txt文件, 格式如上图字典
然后我有一个字幕文件, 格式如以下
21
打死它 abacus 杀了它
00:01:21,190 --> 00:01:22,710
Shoot anything that moves.
abate
救命
00:01:48,200 --> 00:01:49,540
He -- he got me.
abeyance
我最后希望呈现
21
打死它 abacus [abacus是gre词汇 n.算盘]杀了它
00:01:21,190 --> 00:01:22,710
Shoot anything that moves.
abate[abate是gre词汇 v.减轻,降低]
救命
00:01:48,200 --> 00:01:49,540
He -- he got me.
abeyance [abeyance是gre词汇 n.中止,暂搁]
就是加注解这么一个功能吧
ps
我不知道为什么, 一天都没人睬我, 是我态度不正确吗
额, 不会传附件, 如果已经上传, 请把后缀改为,txt
2.zip
(160 Bytes, 下载次数: 0)
gre.zip
(246.58 KB, 下载次数: 10)
|
|