[Tutor] creating files with python and a thanks
Eve Kotyk
e.kotyk@shaw.ca
Sun, 17 Feb 2002 21:48:16 +0000
> function_output = function(param1, param2, ...)
> f = open('myfile.txt', 'w')
> f.write(function_output)
> f.close()
>
> Another possibility is:
>
> f = open('myfile.txt', 'w')
> f.write(function(param1, param2, ...))
> f.close()
Thank you. This is very helpful, but I'm still not quite there. Here
are my results from an Interpreter session.
>>>def gather_data():
items = raw_input("Add food item: ")
portion = input("Enter number of portions: ")
cal_portion = input("Enter calories per portion: ")
output = [items, portion, cal_portion]
#return items,portion,cal_portion
f = open('myfile.txt', 'w')
f.write(str(output))
f.close()
>>> gather_data()
Add food item: cumquats
Enter number of portions: 10
Enter calories per portion: 50
Traceback (innermost last):
File "<pyshell#78>", line 1, in ?
gather_data()
File "<pyshell#75>", line 9, in gather_data
f.write(output)
TypeError: read-only buffer, list
--
ekotyk
http://members.shaw.ca/e.kotyk/virtualstudio.htm