[Tutor] variabel from raw input into re.search?
Evert Rol
evert.rol at gmail.com
Fri Jan 7 14:02:39 CET 2011
Hi Tommy,
> I try to write a program, where the user can write a word or a name and I will tell how many times the subject was mentioned in a text, I’m hosting.
> I guess it’s possible but not this way it seems?
> The re is only searching for the word “name” and not the variable name
> I’m using Python 2.6.6.
> TIA
> Tommy
This looks very much like a problem that was asked just a few days ago. Have a look at the thread at http://mail.python.org/pipermail/tutor/2011-January/081034.html , and see if the solutions offered there can help you.
Cheers,
Evert
> import re
> name = raw_input(’Who would you like to check’? ')
>
> mytxt = open("text.txt", "r")
> antal = []
> for line in mytxt:
> if re.search("(.*)name(.*)", line):
> antal.append(line)
> print name + ' was mentioned ' + str(len(antal)) + ' times in the text,
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list