Python 属性错误:'_io.TextIOWrapper';对象没有属性';追加';

Python 属性错误:'_io.TextIOWrapper';对象没有属性';追加';,python,Python,我一直在尝试使用append属性将内容添加到文本文档中,但它目前不起作用。。。有什么想法吗 MyFile = open("usernames_passwords.txt", "a") print("To sign up you will just need to answer the following questions.") Email = input("Please enter your Email") userUsername = input("Please enter a valid

我一直在尝试使用append属性将内容添加到文本文档中,但它目前不起作用。。。有什么想法吗

MyFile = open("usernames_passwords.txt", "a")
print("To sign up you will just need to answer the following questions.")
Email = input("Please enter your Email")
userUsername = input("Please enter a valid username")
password = input("please enter a password now: ")

userPasswordcheck = input("Please re-enter that password")

if password == userPasswordcheck:
    password_b = password.encode('utf-8')
    password_b_bytes = base64.b64encode(password_b)
    password_b_bytes_re = password_b_bytes.decode('utf-8')
    date_of_birth = input("please enter your date of birth (DD/MM/YY)")
    phone_num = input("please Enter your phone number for extra security (Type '!' if you dont want to enter one)")
    if phone_num == "!":
        phone_num = "_noneGiven_"

    MyFile.append(userUsername)
    MyFile.append(",")
    MyFile.append(password_b_bytes_re)
    MyFile.append(",")
    MyFile.append(Email)
    MyFile.append(",")
    MyFile.append(date_of_birth)
    MyFile.append(",")
    MyFile.append(phone_num)
    MyFile.close()
错误:

AttributeError:“\u io.TextIOWrapper”对象没有属性“append”

尝试:


您需要使用
MyFile.write()
using write()删除文本documjent中的所有数据,这意味着我只能存储1的数据signup@robavioH
file.write()。“删除所有数据”是以写入(“w”)模式打开文件。此外,如果要编写csv文件,请使用stdlib中的
csv
模块。
print("To sign up you will just need to answer the following questions.")
Email = input("Please enter your Email")
userUsername = input("Please enter a valid username")
password = input("please enter a password now: ")
userPasswordcheck = input("Please re-enter that password")

if password == userPasswordcheck:
    with open(filename, "a") as infile:           #Open File in Append Mode
        password_b = password.encode('utf-8')
        password_b_bytes = base64.b64encode(password_b)
        password_b_bytes_re = password_b_bytes.decode('utf-8')
        date_of_birth = input("please enter your date of birth (DD/MM/YY)")
        phone_num = input("please Enter your phone number for extra security (Type '!' if you dont want to enter one)")
        if phone_num == "!":
            phone_num = "_noneGiven_"
        to_write = [userUsername, password_b_bytes_re, Email, date_of_birth, phone_num]
        infile.write(", ".join(to_write) + "\n")     #Append Content