Does anyone know where I can read up on how to search for a particular object in a file? For example, search for a particular word in a dictionary?
searching within a file
Collapse
X
-
-
Not much to it really:[code=Python]>>> f = open(r'C:\SDS2_ 7.0\jobs\60801_ Baylor\macro\De epEllumRad1.txt ')
>>> for line in f:
... if 'Deep Ellum' in line:
... print line
...
# Deep Ellum radii and cons lines at Canopy 1 (B-D)
>>> f.close()
>>> [/code]Do you have a specific problem you are trying to solve?Comment
-
Originally posted by bvdetNot much to it really:[code=Python]>>> f = open(r'C:\SDS2_ 7.0\jobs\60801_ Baylor\macro\De epEllumRad1.txt ')
>>> for line in f:
... if 'Deep Ellum' in line:
... print line
...
# Deep Ellum radii and cons lines at Canopy 1 (B-D)
>>> f.close()
>>> [/code]Do you have a specific problem you are trying to solve?
Thanks for the advice.
I'm trying to create a spell checker which can spell check either a single word or a file depending on what the user chooses. The spell checker is really simple though, it doesn't point out a word that is spelled wrong, however it checks two different files to see if the word(s) is/are typed in are contained in either file. One of the files is a dictionary file with a list of words, and the other file is the user dictionary, created by the user.Comment
-
Originally posted by LolaTThanks for the advice.
I'm trying to create a spell checker which can spell check either a single word or a file depending on what the user chooses. The spell checker is really simple though, it doesn't point out a word that is spelled wrong, however it checks two different files to see if the word(s) is/are typed in are contained in either file. One of the files is a dictionary file with a list of words, and the other file is the user dictionary, created by the user.Comment
-
Code:import re authorpattern = "<meta name="AUTHOR" content="(.*?)"><meta name=" patt = re.compile(authorpattern,re.IGNORECASE) authors = re.findall(patt,data) or if you need only 1 author amatch = re.search(source.authorpattern,data,re.IGNORECASE) author = amatch.group(1)
Comment
-
Originally posted by anonymousCode:import re authorpattern = "<meta name="AUTHOR" content="(.*?)"><meta name=" patt = re.compile(authorpattern,re.IGNORECASE) authors = re.findall(patt,data) or if you need only 1 author amatch = re.search(source.authorpattern,data,re.IGNORECASE) author = amatch.group(1)
I welcome your contributions here in the Python forum. I must, however, that you useCode:tags any time that you post executable lines. And [CODE=python]# Adding =python to them makes them look even better.
Comment
-
thanks again to everyone for their help.
i'm encountering a major problem with my project though.
i'm supposed to take the file named dict.txt which has quite the amount of words
and turn it into a list.
i know how to do it (at least i think so) but my program keeps shutting down, i'm guessing because the file is pretty large.
any suggestions?Comment
Comment