File write() problem

apriebe47 at gmail.com apriebe47 at gmail.com
Wed Dec 27 03:21:43 EST 2006


Alright, I realize this is probably very basic to be posted on this
newsgroup but I cannot figure out what is causing my problem. Here is
the code I am using below:

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 file"
        configfile.write(pwd2)
        serverPassword = configfile.readline()
        configfile.close()

Now when I look at the file, I can see the password that I had typed
in, but there are also a bunch of symbols that are added to the text
file as well. My question is how can I write just the password to the
text file and not any extra 'garbage'. Thanks!

Andrew




More information about the Python-list mailing list