简体   繁体   English

AttributeError:'_io.TextIOWrapper'对象没有属性'append'

[英]AttributeError: '_io.TextIOWrapper' object has no attribute 'append'

I have been trying to add things to my text document using the append attribute but it is currently not working... any ideas? 我一直在尝试使用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()

The error: 错误:

AttributeError: '_io.TextIOWrapper' object has no attribute 'append' AttributeError:'_io.TextIOWrapper'对象没有属性'append'

Try: 尝试:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python “AttributeError: '_io.TextIOWrapper' object has no attribute 'append'” 错误 - Python “AttributeError: '_io.TextIOWrapper' object has no attribute 'append'” error Python-AttributeError:“ _ io.TextIOWrapper”对象没有属性“ append” - Python - AttributeError: '_io.TextIOWrapper' object has no attribute 'append' AttributeError:'_io.TextIOWrapper'对象没有属性'append'吗? - AttributeError: '_io.TextIOWrapper' object has no attribute 'append'? Python-错误-AttributeError:“ _ io.TextIOWrapper”对象没有属性“插入” - Python - Error - AttributeError: '_io.TextIOWrapper' object has no attribute 'insert' AttributeError: '_io.TextIOWrapper' 对象没有 txt 文件的属性 'lower' - AttributeError: '_io.TextIOWrapper' object has no attribute 'lower' for txt file AttributeError: '_io.TextIOWrapper' 对象没有属性 'next' python - AttributeError: '_io.TextIOWrapper' object has no attribute 'next' python AttributeError:'_io.TextIOWrapper'对象没有属性'next'? - AttributeError: '_io.TextIOWrapper' object has no attribute 'next'? Python说:AttributeError:'_io.TextIOWrapper'对象没有属性' - Python says: AttributeError: '_io.TextIOWrapper' object has no attribute ' AttributeError:'_io.TextIOWrapper'对象没有属性'decode' - AttributeError: '_io.TextIOWrapper' object has no attribute 'decode' AttributeError:'_io.TextIOWrapper'对象没有属性'split'错误 - AttributeError: '_io.TextIOWrapper' object has no attribute 'split' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM