0

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 ?

1
  • Do you use Python 2.7? Commented Sep 23, 2018 at 0:17

2 Answers 2

1

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.

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

1 Comment

You are right, my remote interpretter was python 2.7 which caused the issue. changing it to python 3 resolved the problem
1

Make it a string on input

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

5 Comments

I forgot to mention, if there are only numbers in an input, python automatically assumes that its an integer
I do not want it to assume that, essentially those are dashes in between I guess python thinks it is a negative number ??
I know you don't want it to assume that, so do what I said to do in my answer :D
That does not solve my problem, the return value of input function changes the input entirely.. changing its type alone won't help
Why-ever not? Did you try it?

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.