NEED HELP- read file contents, while loop to accept user input, and enter to exit

Cathy James nambo4jb at gmail.com
Tue May 24 04:31:37 EDT 2011


dear mentor,

I need help with my code:
1) my program won't display file contents upon opening
2) my program is not writing to file
3) my program is not closing when user presses enter- gow do I do this with
a while loop?

please see my attempt below and help:

#1) open file and display current file contents:
f = open ('c:/testing.txt'', 'r')
f.readlines()
#2)  and 3) use while loop  to write user input to file, save to file, close
when press enter:
while True:
    s = input ('enter name: ').strip()
    f = open ('c:/testing.txt', 'a')
    if f.writable():
        f.write(s)
        break
    else:
        f = open ('c:/testing.txt', 'r')
        f.readlines()
        for line in f:
            print (line)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110524/6a9d9e99/attachment.html>


More information about the Python-list mailing list