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?
7 1540 - file("file name.txt", 'rb')
-
fil.find("word")
bvdet 2,851
Expert Mod 2GB
Not much to it really: - >>> f = open(r'C:\SDS2_7.0\jobs\60801_Baylor\macro\DeepEllumRad1.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()
-
>>>
Do you have a specific problem you are trying to solve?
Not much to it really: - >>> f = open(r'C:\SDS2_7.0\jobs\60801_Baylor\macro\DeepEllumRad1.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()
-
>>>
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.
bvdet 2,851
Expert Mod 2GB
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.
You are welcome. Let us know how the project goes for you.
- 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)
- 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)
Hello, annonymous! I'm impressed: 49 posts; C++, Java, MySQL, now Python and a regex to boot.
I welcome your contributions here in the Python forum. I must, however, that you use [code] tags any time that you post executable lines. And - # Adding =python to them makes them look even better.
Thank you.
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James |
last post by:
We have a need to search through an entire drive for a specific file name.
The process is currently written with recursive loops through each directory
and the Scripting.FileSystemObject. Problem...
|
by: Alan Mackenzie |
last post by:
I've recently moved onto a C++ project with a large number of directories
(several hundred) containing an even larger number of C++ source files.
There are vastly more ways in C++ to obfuscate a...
|
by: kids |
last post by:
Hi all,
i have 2 files, 1 file that store 1000 records of name entries and
it's key ID. With the sorting function all the records have been sorted and
its correspond key id was store in a sorted...
|
by: Walter Dnes (delete the 'z' to get my real address |
last post by:
I took a C course some time ago, but I'm only now beginning to use it,
for a personal pet project. My current stumbling-block is finding an
efficient way to find a match between the beginning of a...
|
by: silver_animal |
last post by:
Greetings,
Hopefully this posting is clear to both newsgroups.
I have been looking for a way to open a PDF file and automatically
locate and go to a certain phrase within the file. The phrase...
|
by: jaysherby |
last post by:
I'm new at Python and I need a little advice. Part of the script I'm
trying to write needs to be aware of all the files of a certain
extension in the script's path and all sub-directories. Can...
|
by: SSJVEGETA |
last post by:
Hello, everybody. I have read some examples and manuals for the egrep command for Linux and I don't know if this egrep command is right for the particular files I am searching for. Here is what the...
|
by: Ahmad Jalil Qarshi |
last post by:
Hi,
I have a text file having size about 2 GB. The text file format is like:
Numeric valueAlphaNumeric values
Numeric valueAlphaNumeric values
Numeric valueAlphaNumeric values
For example...
|
by: Gene Kelley |
last post by:
Hello PHPers,
I'm trying to get at a single line within a text file. For instance, I
want to print the line within a the file named "file.txt" that starts
with "17:".
file.txt contains...
|
by: Sevla |
last post by:
hello guys
i set this code , and i would like to know if its possible set "quotes" on the searched word.
Thank You
#word searching program within a txt file
#!C:/perl/bin/perl.exe
start:
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |