files and reading from them

Greg Krohn infinitystwin.SPAM at IS.BAD.yahoo.com
Mon Mar 25 02:29:03 EST 2002


"Avi Homes" <Moo at houston.rr.com> wrote in message
news:auzn8.71680$Vl.2635455 at typhoon.austin.rr.com...
> I am writing a dictionary to a file, like so
> f.write(str(Info))
>
> and what it is writing to the file is the following..
> {'IPrice': '3', 'IName': 'lame lame', 'IDesc': 'stuff}
>
> and if i write in two things, i get..
> {'IPrice': '3', 'IName': 'lame lame', 'IDesc': 'stuff}
> {'IPrice': '2', 'IName': 'notworking, 'IDesc': 'annoying'}
>
> What i would like to do is pull a readline or somesuch.. and have it take
in
> the whole thing, and then just let me assign that to a empty name, and
turn
> it into a new dictionary.. like say
>  file.seek(1)
> //thats how i'd go to the first place in the file correct?
> X=file.readline()
>
> and now i can say print X['IName'] ... and its turned into a dictionary..
i
> am most likely going about this *all* wrong.

I'm assuming that you just want to create a dictionary from each line in
your file.
all you need is eval(). Like this:

dict1 = eval(file.readline())
dict2 = eval(file.readline())
...
etc.


greg





More information about the Python-list mailing list