I have seen some code (e.g. this tutorial from dropbox) that probably needs to work for quite a wile with Python 2.X but probably also with Python 3.X
How should those projects deal with raw_input
?
I think something like
#!/usr/bin/env python
def input_string(question=""):
"""A function that works for both, Python 2.x and Python 3.x.
It asks the user for input and returns it as a string.
"""
import sys
if sys.version_info[0] == 2:
return raw_input(question)
else:
return input(question)
# Example
answer = input_string("What is your name? ")
print(answer)
might be a good way, but I am not too sure about it.
Are there "official" advice (e.g. in form of PEPs) how to deal with it? How is this done by now?