[Tutor] Brain Dead
Daniel Yoo
dyoo@hkn.EECS.Berkeley.EDU
Fri, 11 Aug 2000 11:34:01 -0700 (PDT)
On Fri, 11 Aug 2000 sysadmin@hiretechs.com wrote:
> O.K., I am retarted. I created a simple, little piece of python code.
> I opened a txt. file from my desktop changed it around, did a little of
> this and a little of that and everything worked great. Now I am so brain
> fried that I can't remember how to print the results into a new file.
> Please when
> you are done laughing at me. Will you give me a quick reminder. Thanks.
Don't worry about it. And we'd never laugh at you --- we're here to help
each other.
Files can be opened for writing by specifying 'w' (write) or 'a'
(append) as the second parameter in an open() call:
f = open('secrets.txt', 'w')
Afterwards, you can start doing write()'s:
f.write('This is a test.')
There's a section in the official tutorial that talks about file i/o:
Section 7.2 Reading and Writing files:
http://www.python.org/doc/current/tut/node9.html#SECTION009200000000000000000