files and reading from them
usenet at thinkspot.net
Mon Mar 25 08:24:10 CET 2002
On Mon, 25 Mar 2002 06:30:30 GMT, "Avi Homes" <Moo at houston.rr.com> wrote in
comp.lang.python in article <auzn8.71680$Vl.2635455 at typhoon.austin.rr.com>:
> 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
> //thats how i'd go to the first place in the file correct?
> and now i can say print X['IName'] ... and its turned into a dictionary.. i
> am most likely going about this *all* wrong.
Technically, you can accomplish this by
x = eval(file.readline())
if you know for a fact that your line of text from the file will be a
correctly formatted, string representation of a dictionary, and that you
can depend on that 100%, no ifs, ands or buts.
Whether this is the best way to accomplish what you want is another
Shelve and pickle (as mentioned elsewhere) are some modules that should
More information about the Python-list