19

as the title says, in python, I'm trying to make it so when someone types in a choice (in this case Choice13) then it deletes the old password from the list passwords and adds the new one instead.

passwords = ['mrjoebblock' , 'mrjoefblock' , 'mrjoegblock', 'mrmjoeadmin' ]
if choice == '3':
    password = raw_input('Welcome admin! I\'m going to need your password ')
        if password == 'mrjoeadmin':
            print('Welcome Mr. Joe!')
            Choice11 = raw_input('What would you like to do? Press 1 for changing your admin password, 2 for viewing a class\'s comments, or 3 for changing a class\'s password')
            if Choice11 == '1':
                print('You have chosen to change your password! ')
                Choice12 = raw_input('You will need to put in your current password to access this feature ')
                if Choice12 == 'mrmajoeadmin':
                    Choice13 = raw_input('What would you like to change your password to? ')
                    passwords.remove('mrjoeadmin')
                    passwords.append = Choice13
1
  • 10
    i think you mean to call passwords.append(Choice13) Commented Oct 26, 2015 at 21:10

2 Answers 2

42

To append something to a list, you need to call the append method:

passwords.append(Choice13)

As you've seen, assigning to the append method results in an exception as you shouldn't be replacing methods on builtin objects -- (If you want to modify a builtin type, the supported way to do that is via subclassing).

Sign up to request clarification or add additional context in comments.

Comments

3

or you could modify the same list slot by doing:

passwords[passwords.index('mrjoeadmin')] = Choice13

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.