我的文件不会写入文本文件,它只是在下面打印



我已经尝试了几种不同的方法,但我似乎无法修复它。在底部,它只创建.txt文件,但不添加任何变量并保持为空。然后,它开始在shell中其余代码下方打印用户名和密码。输入用户名和密码并在下面打印,而.txt文件仍为空。

un = input("What is your username?")
npw = input("Please enter new password.")
npwc = input ("Please confirm new password")
if npwc == npw:
    if npwc.isupper()== False:
        if npwc.islower()== False:
            if len(npwc) >= 8:
                if str.isdigit(npwc) == False:
                    npw=npwc
                    print("Your paswsword has been changed")
                else:
                    print("Your password must contain a number")
            else:
                print("Your password must contain at least 8 characters.")                
        else:
            print("Your password must contain at least 1 upper case character.")
else:
    print ("Passwords don't match")
pw = npwc
file=open("PasswordSheet.txt","a")
file.write(input(un, ", ", pw))
file.close()
file.write(input(un + ", " + pw))

应该是

file.write(un + ", " + pw)

相关内容

最新更新