0

I am creating a program on python that allows you to create a username and password and here's what I have so far:

#Code
username = str(input("Please enter a username:"))
print("Your username is",username,",proceed?")
raw_input = input()
if raw_input() == 'no':
    re_u = input("Please re-enter username")
else:
    import getpass
    mypass = getpass.getpass("Please enter your password:")

And the trouble i'm receiving is: Traceback (most recent call last): line 6, in if raw_input() == 'no': TypeError: 'str' object is not callable.

Please help

1
  • are you writing this in python 2.7 or 3.x? Commented Nov 12, 2016 at 21:24

2 Answers 2

1

In the Line:

raw_input = input()

If you are using python 2.7, You are overriding the default raw_input and making it a string.

If you are using python 3, you are creating a string raw_string with the value of input()

So, in both cases, when you try to call raw_input like a function, you will receive the error.

TypeError: 'str' object is not callable.

if raw_input() == 'no':

Here, raw_input is a string, not a callable. You can not call it like a function.

Now, so the working code should be like below: (A python 2.7 solution)

import getpass

username = raw_input("Please enter a username:")
username_confirmation = raw_input("Your username is " + username + ",proceed?")
if username_confirmation == "No":
    username = raw_input("Please re-enter username")
else:
    password = getpass.getpass("Please enter your password:")

# do something with username and password
Sign up to request clarification or add additional context in comments.

3 Comments

If this is Python 3, then raw_input isn't a default method anymore, since it was renamed to input instead.
@Makoto I got the feeling that this is python 2, because OP is surely a beginner and using raw_input() wrongly. If this is python 3, he shouldn't be familiar with it. Anyway, I have edited the answer for both the cases.
print became a function in Python 3, and input behaves the same as raw_input did in Python 2 (as in Python 2, input did something distinct too). I strongly doubt that the OP is using Python 2, but thanks for correcting it.
0

raw_input is a string, but you're trying to use it as a function with the () at the end of it. use this instead:

if raw_input == 'no':

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.