files and reading from them

Sheila King usenet at thinkspot.net
Mon Mar 25 02:24:10 EST 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
>  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.

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
question.

Shelve and pickle (as mentioned elsewhere) are some modules that should
help, possibly.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list