Ahmed
Ahmed

Reputation: 15069

pycharm input returns an int instead of string?

I am new to python programming. I am using latest version of pyCharm and doing remote debugging of some code which is on raspberrypi. There is this code.

# Get the verifier code from the user. Do this however you
# want, as long as the user gives the application the code.
verifier = input('Verifier code: ')

Where I enter some string like 117-820-181 on the console window and in the veriifer variable it shows up as an int. on the next line the code breaks as it expects verifier to be string and not int. Any ideas why this is returning int instead of string ?

Upvotes: 0

Views: 1293

Answers (2)

lyxal
lyxal

Reputation: 1118

I believe that you are using Python 2.x (input in that version evaluates the given input as code, which is what seems to be happening. Also, I think that PyCharm likes to use Python 2.x rather than 3.x).

If this is so, then use raw_input() (which returns everything as a string, much like Python 3.x’s input() function does):

verifier = raw_input('Verifier code: ')

This will stop the issue where the verification code is turned into an integer.

Upvotes: 1

damaredayo
damaredayo

Reputation: 1077

Make it a string on input

    verifier = str(input('Verifier code: '))

Upvotes: 1

Related Questions