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 li
Hello,
First I'm not so clear about your problem, but you can do the following
steps:
1. Transform your file into list (list1)
2. Use regex to capture 'robert' in every member of list1 and add to
list2
3. Transform your list2 into a file
pujo
--
http://mail.python.org/mailman/listinfo/python-
import re
name = "Robert"
f = file('phonebook.txt','r')
lines = [line.rstrip("\n") for line in f.readlines()]
pat = re.compile(name, re.I)
related_lines = [line for line in lines if pat.search(line)]
And then you write the lines in related_lines to a file. I don't really
write text to files much s
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
I think you need to get a database. Anyways, if anything, it should
create no more than 5,000 files, since 5,000 facts shouldn't talk about
30,000 animals. There have been a few discussions about looking at
files in directories though, if you want to look at those.
--
http://mail.python.org/mailm
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
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
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
Oh, I seem to have missed the part saying 'or other word'. Are you
doing this for every single word in the file?
--
http://mail.python.org/mailman/listinfo/python-list
Yes, I am. Does that make it harder.
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 12 Jul 2005 08:25:50 -0700, rorley wrote:
> 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 ac
As Steven said this looks too much like home work
But what the heck I am also learning python. So I wrote a small
program. A very small program. I am fairly new to Python, I am stunned
each time to see how small programs like this can be.
Since I am also learning can somebody comment if anything h
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
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
[EMAIL PROTECTED] wrote:
> 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
>
No. There is utterly no reason why you should create 5000 or 3 text
files. While you are waiting to get a clue about databas
On Wed, 13 Jul 2005 11:38:44 +1000, John Machin wrote:
> [EMAIL PROTECTED] wrote:
>> 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
>>
>
> No. There is utterly no reason why you should create 5000 or 300
16 matches
Mail list logo