Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么不';我不能在它们的原始来源列表中找到这些词吗?_Python_Regex_Python 2.7 - Fatal编程技术网

Python 为什么不';我不能在它们的原始来源列表中找到这些词吗?

Python 为什么不';我不能在它们的原始来源列表中找到这些词吗?,python,regex,python-2.7,Python,Regex,Python 2.7,我试图在两个不同的文件中查找中文单词,但它不起作用,所以我尝试在从中获取单词的同一个文件中搜索这些单词,但似乎也找不到?怎么可能呢 chin_split = codecs.open("CHIN_split.txt","r+",encoding="utf-8") 用于正则表达式代码 import re for n in re.findall(ur'[\u4e00-\u9fff]+',chin_split.read()): print n in re.findall(ur'[\u4e00-

我试图在两个不同的文件中查找中文单词,但它不起作用,所以我尝试在从中获取单词的同一个文件中搜索这些单词,但似乎也找不到?怎么可能呢

chin_split = codecs.open("CHIN_split.txt","r+",encoding="utf-8")
用于正则表达式代码

import re
for n in re.findall(ur'[\u4e00-\u9fff]+',chin_split.read()):
    print n in re.findall(ur'[\u4e00-\u9fff]+',chin_split.read())    
为什么我只打印了<代码>错误

仅供参考,我尝试过这样做,但效果良好:

for x in [1,2,3,4,5,6,6]:
    print x in [1,2,3,4,5,6,6]
顺便说一句

chin_split
包含英语、希伯来语和汉语的单词

chin_split.txt
中的一些行:

 he daodan   核导弹     טיל גרעיני     
 hedantou    核弹头     ראש חץ גרעיני      
 helu    阖庐  "ביתו, מעונו 
 helu    阖庐   שם מלך וו בתקופת ה'אביב והסתיו'"      
 huiwu   会晤  להיפגש עם      

您多次读取文件描述符,这是错误的

第一个
chin\u split.read()
将产生所有内容,但其他内容(在循环中)将只得到一个空字符串


这个循环毫无意义,但如果您想保留它,请先将文件内容保存在变量中。

如果可以,请切换到Python 3,它对Unicode有更好的支持。