在文件中查找人名 [英] Finding Peoples' Names in Files
问题描述
疯狂的问题,但是有没有人尝试过这个或者看过这个/ b $ b的Python代码呢?例如,如果文本文件包含''Guido''或''Robert''和
或''Susan'',那么我们应该返回True,否则返回False。
Crazy question, but has anyone attempted this or seen Python code that
does? For example, if a text file contained ''Guido'' and or ''Robert'' and
or ''Susan'', then we should return True, otherwise return False.
推荐答案
10月11日下午5:22,brad< byte8b ... @ gmail.comwrote:
On Oct 11, 5:22 pm, brad <byte8b...@gmail.comwrote:
疯狂的问题,但是有没有人尝试过这个或看过的那些
的Python代码呢?例如,如果文本文件包含''Guido''或''Robert''和
或''Susan'',那么我们应该返回True,否则返回False。
Crazy question, but has anyone attempted this or seen Python code that
does? For example, if a text file contained ''Guido'' and or ''Robert'' and
or ''Susan'', then we should return True, otherwise return False.
你不能只使用字符串函数.findall()吗?
Can''t you just use the string function .findall() ?
2007年10月11日,brad< by ******* @ gmail.comwrote:
On 11/10/2007, brad <by*******@gmail.comwrote:
疯狂的问题,但有人试过这个或看过Python
的代码呢?例如,如果文本文件包含''Guido''或''Robert''和
或''Susan'',那么我们应该返回True,否则返回False。
-
http:// mail。 python.org/mailman/listinfo/python-list
Text = open(fname).read()
def a_function():
代表[''Guido'',Robert'',Susan'']的名字:
如果文字名称:
返回1
如果a_function():
print"找到了一个名字
:)
Text = open(fname).read()
def a_function():
for Name in [''Guido'', Robert'',Susan'']:
if Name in Text:
return 1
if a_function():
print "A name was found"
:)
co ****** ***@gmail.com 写道:
10月11日下午5:22,brad< byte8b ... @ gmail.comwrote:
On Oct 11, 5:22 pm, brad <byte8b...@gmail.comwrote:
>疯狂的问题,但有没有人尝试过这个或看过的
代码?例如,如果文本文件包含''Guido''或''Robert''和
或''Susan'',那么我们应该返回True,否则返回False。
>Crazy question, but has anyone attempted this or seen Python code that
does? For example, if a text file contained ''Guido'' and or ''Robert'' and
or ''Susan'', then we should return True, otherwise return False.
你不能只使用字符串函数.findall()吗?
Can''t you just use the string function .findall() ?
我的意思是*任何*可能的人的名字......我不知道*名字
事先:)
I mean *any* possible person''s name... I don''t *know* the names
beforehand :)
这篇关于在文件中查找人名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!