In 2.6, if I needed to accept input that allowed a percent sign (such as “foo % bar”), I used raw_input() which worked as expected.
In 3.0, input() accomplishes that same (with raw_input() having left the building).
As an exercise, I’m hoping that I can have a backward-compatible version that will work with both 2.6 and 3.0.
When I use input() in 2.6 and enter “foo % bar”, the following error is returned:
File "<string>", line 1, in <module>
NameError: name "foo" is not defined
…which is expected.
Anyway to to accomplish acceptance of input containing a percent sign that works in both 2.6 and 3.0?
Thx.
You can use
sys.version_infoto detect which version of Python is running.Alternatively, if you don’t want to override Python 2.X’s builtin
inputfunction, you can writeAlthough, even in my first code sample, the original builtin
inputis always available as__builtins__.input.