File write() problem

apriebe47 at gmail.com apriebe47 at gmail.com
Wed Dec 27 04:19:44 EST 2006


Marc 'BlackJack' Rintsch wrote:

> > configfile = file('config.txt', 'w')
> > serverPassword = configfile.readline()

Hrm. When I run the code that I posted I don't seem to get those
errors.

> Please post the exact code you have trouble with.  Don't retype it -- copy
> and paste it.

from getpass import getpass

configfile = file('config.txt', 'w')
serverPassword = configfile.readline()
if serverPassword == '':
   print "Server warning: No password has been set!"
   pwd1 = getpass("New Password: ")
   pwd2 = getpass("Confirm Password: ")
   while pwd1 != pwd2:
       print "Passwords did not match."
       pwd1 = getpass("New Password: ")
       pwd2 = getpass("Confirm Password: ")
   print "Password set. Storing to admin/config..."
   configfile.write(pwd2)
   serverPassword = configfile.readline()
   configfile.close()

Again I tested the code before I posted and I get no errors, just not
the result I am looking for in the text file. Thanks for taking the
time to look at it.

Andrew




More information about the Python-list mailing list