Python Language Incompatibilities moving from Python 2 to Python 3 User Input

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


In Python 2, user input is accepted using the raw_input function,

Python 2.x2.3
user_input = raw_input()

While in Python 3 user input is accepted using the input function.

Python 3.x3.0
user_input = input()

In Python 2, the input function will accept input and interpret it. While this can be useful, it has several security considerations and was removed in Python 3. To access the same functionality, eval(input()) can be used.

To keep a script portable across the two versions, you can put the code below near the top of your Python script:

    input = raw_input
except NameError:

Got any Python Language Question?