[Tutor] Saving data
Deirdre Saoirse
deirdre@deirdre.net
Mon, 18 Oct 1999 15:40:48 -0700 (PDT)
On Mon, 18 Oct 1999, Alexandre Passos wrote:
> How can I save some data achieved in some program into other file?
> ex:
>
> nm = raw_input("Name:")
> age = input("Age:")
> hob = raw_input("Favourite hobby:")
> persnon = """Name:%s
> Age:%d
> Favourite Hobby: %s"""
One simple way:
f = open("savefile", "w+")
z = "Name:" + nm + '\n'
f.write(z)
(etc)
f.close()
That way, each variable is listed on each line. Otherwise you have to make
sure there's no returns in there. :)
To retrieve, use f.read() or f.readline() after opening it for reading
(the above example would be opening it for writing).
--
_Deirdre * http://www.linuxcabal.net * http://www.deirdre.net
"Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator
"That's because the Martians keep shooting things down." -- Harlan Rosenthal
<Harlan.Rosenthal@Dialogic.com>, retorting in Risks Digest 20.60