[Tutor] creating files with python and a thanks

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


On Sat, 16 Feb 2002 20:26:59 -0800, Sheila King <sheila@thinkspot.net>
wrote about Re: [Tutor] creating files with python and a thanks:

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

OH, I forgot to include the case, for where the function returns
something that isn't a string...like it returns an integer, float, list,
dictionary, or what-have-you.

How about this?

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

Basically, wrapping
str()

around anything will convert it to it's "string" representation, if that
is possible. For most of the basic types, I can't imagine a problem.

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

"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_