[Tutor] Simple Question

Magnus Lycka magnus@thinkware.se
Sat Dec 14 19:07:01 2002


At 18:16 2002-12-14 -0500, Kyle Babich wrote:
>How do I create a file?
>I was always under the impression that if I attempted to open a file that
>didn't exist then the file would be created automatically.  Now that I need
>something like that it doesn't happen.  I have 2.2.2 running on XP Home.

By default, you open files just to read them.
You can't read from a new file...

f = file('newfile.txt', 'w')
f.write('some text\n')
f.close()

See http://www.python.org/doc/current/lib/built-in-funcs.html



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se