RSS Forums RSS
Please support our Python advertiser: Programming Forums

Searching a text file

Join Date: Mar 2007
Posts: 1
Reputation: emzy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
emzy emzy is offline Offline
Newbie Poster

Searching a text file

  #1  
Mar 28th, 2007
Hi All,

I'm having huge problems with a program that i am attempting to write. What i have is a program that prints Acronyms and sentences to a text file already, now i am trying to create a new program that reads that text file and if the user inputs the same acronym, it will print out the sentence associated with that acronym. This is what i have so far;

import string

def main():

acronymName = raw_input("Enter a sentence that may include more than one acronym ")
fileHandle = open ( 'acronym.txt', 'r' )

for line in fileHandle.readlines():
for acronym in line.split():
if acronym.enswith('nce'):
print acronym


fileHandle.close()

main()


Obviously Im not even sure if i am on the right track. Any help would be appreciated. I can't even seem to find a similar program to compare to.

Thanks Heaps..
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:24 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC