Help with inverted dictionary

2005-07-12 Thread rorley
I'm new to Python and I'm struggling.  I have a text file (*.txt) with
a couple thousand entries, each on their own line (similar to a phone
book).  How do I make a script to create something like an inverted
dictionary that will allow me to call "robert" and create a new text
file of all of the lines that contain "robert"?


Thanks so much.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
OK, so my problem is I have a text file with all of these instances,
for example 5000 facts about animals.  I need to go through the file
and put all of the facts (lines) that contain the word lion into a file
called lion.txt.  If I come across an animal or other word for which a
file does not yet exist I need to create a file for that word and put
all instances of that word into that file.  I realize that this should
probably create 30,000 files or so.  Any help would be REALLY
appreciated.  Thanks.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
I will transfer eventually use a database but is there any way for now
you could help me make the text files?  Thank you so much.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
I will transfer eventually use a database but is there any way for now
you could help me make the text files?  Thank you so much.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
I will transfer eventually use a database but is there any way for now
you could help me make the text files?  Thank you so much.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
Yes, I am.  Does that make it harder.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
Not quite homework but a special project.  Thanks for the advice.  I'll
let you know if I run into anymore stumbling blocks.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with inverted dictionary

2005-07-12 Thread rorley
Thanks for the hints, I think I've figured it out.  I've only been
using Python for 2 days so I really needed the direction.  If you were
curious, this is not homework but an attempt to use the ConceptNet data
(its an MIT AI project) to make a website in a Wiki-like format that
would allow the data to be edited on the fly.  I'll ask again if I need
more help.  You guys are great.  Reece

-- 
http://mail.python.org/mailman/listinfo/python-list


Help with mass remove in text file

2005-07-13 Thread rorley
I'm trying to open a text file, remove all instances of the words
"f=x;" and "i=x;" where x can be any number 0-14.  Also, I want to
remove all {   " or ) or ( or '   } each time one of those characters
occurs respectively.  This is what I've been able to piece together...


import os, string
x = ("f=;")
y = ("i=;)
inputFile = open('abcd.txt','r')
   data = inputFile.read()
   inputFile.close()
   search = string.find(data, x)
   if search >=1:
  data = data.replace(x)
  data = data.replace(y)
  outputFile = open('abcd.txt','w')
  outputFile.write(data)
  outputFile.close()


This doesn't work, even to just remove "f=;".  Any help would be great.

Thanks,
Reece

-- 
http://mail.python.org/mailman/listinfo/python-list