Question about files?

Lie Lie.1296 at gmail.com
Sun Jun 1 21:06:11 CEST 2008


On Jun 1, 1:44 am, corvettecra... at gmail.com wrote:
> I want to create a program where a user can type what ever they want
> to, have it saved to a file, and the be able to re-open it and read
> it. How would I do this? Thanks!

Use a multi-line text-input widget (available on any widget library)

To open a file in python for reading:
filepointer = file('path/to/file', 'r')

then read it like this:
for line in filepointer:
    dosomethingwith(f)

or:
filecontent = filepointer.read()

To open a file for writing:
filepointer = file('path/to/file', 'w')

to write to a file:
filepointer.write(somestring)




More information about the Python-list mailing list