[Tutor] ideas on how to process a file
Spencer Parker
inthefridge at gmail.com
Fri Apr 10 18:04:49 CEST 2009
I forgot to respond back to the list:
The only info I really need is the name. So I have been using readlines()
to go through and find the lines that have fullname,
if line.find("FULLNAME")>=0:
I am now having issues with it writing it to a file.
This is my code:
http://pastebin.com/m11053edf
I have it printing each line to the console just fine. But when I write it
to a file it only writes the last line it finds.
I got this figured out...I had the write_file in the wrong spot. It was
just overwriting the file each time. Thanks again!
On Fri, Apr 10, 2009 at 9:24 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:
>
> "Spencer Parker" <inthefridge at gmail.com> wrote in message
>
> I have a flat file database that I want to get information from. The
>> basic
>> text looks like this:
>>
>> ITEM {
>> "FULLNAME" "apps114.chgit.com!file:/etc"
>> "RECOVERY" "0"
>> }
>>
>> They are all on a separate line in the text file. I had thought about
>> trying to drop it into a list or a dictionary. Most likely a dictionary.
>>
>
> What would be the key and what would be the data?
>
> With a regular structure delimited by braces you should be able
> to process the file line by line fairly easily.
>
>
> thought about using regular expressions to pull the data I need.
>>
>
> You probably don;t need regex, but it depends on what exactly
> you want to filter/extract.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090410/0a71ef4a/attachment-0001.htm>
More information about the Tutor
mailing list