[Tutor] creating files with python and a thanks

Sheila King sheila@thinkspot.net
Sat, 16 Feb 2002 20:26:59 -0800

On Sun, 17 Feb 2002 03:59:05 +0000, Eve Kotyk <e.kotyk@shaw.ca>  wrote
about Re: [Tutor] creating files with python and a thanks:
> > f = open('myfile.mbg', 'w')
> > f.write('this is my file\nmy stuff\nis in\nmy\nfile')
> > f.close()
> > 
> This is interesting to me for my project.  So if instead of f.write
> ('this is my file...., ..) I wanted to write the whole input and output
> of a function to a file how would I do that?

If the function returns a string, then one possibility is:

function_output = function(param1, param2, ...)
f = open('myfile.txt', 'w')

Another possibility is:

f = open('myfile.txt', 'w')
f.write(function(param1, param2, ...))

As in all things Python, always have an Interpreter window open and just
play around and experiment. I would make up some dummy files (not
important ones) to do this type of experimenting with. But you will most
likely not hurt anything, and it is the best way to learn.

Sheila King

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_