python3 is far from being python29 Mar 2016
From what I know, Python as a programming language was designed to be simple both from a usability and debuggability standards. This helped me learn how to be a better programmer when I started with python 2.7.
Things have changed since then, only for the worse unfortunately.
Look at the simple code snippet below:
Fairly simple. It just takes in the input from
and passes to a reverseList() method. Nothing fancy. Works perfectly fine on python 2.7.
However, this does not work on python 3.
My best guess after trying this out in both python 3 and python 2.7 environments is that
the behaviour of the
input() has changed since between the revisions. My guess
again behind the change makes me think it was done to make people write better and more robust
code as most security based attacks happen by parsing non sanitized input from
It seems as if the
input() function is a lot dumber in some sense in python 3.
It seems to parse everything character by character, while as in python 2.7, if I format the
input like a string:
[1, 2, 3, 4], it’s able to delimit it and parse it properly
without any explicit type casting needed.
In retrospect, this is annoying. Python as a language is supposed to be simple without the user having to worry about such issues. My friend whose still new to learning python couldn’t figure this out without me jumping in and trying stuff.
I don’t know of one yet. I’m still trying to find if what I assumed to be different with the
input() function is actually true or not.
So this was an oversight on my part. Turns out that I had two extra square brackets on line 5 which is translates to a list in python 3. I’m surprised this works with python 2.7 as the behavior should be what python 3 suggests.
But in the meantime, I can only assume that a better way to solve this would be to actually
manually build the list yourself from
stdin rather than having to rely on python
to do so. While this sounds backwards in terms of functionality and ease of use for beginners,
it does help solve the fact that people would be a bit more careful as to what they will and
can pass in to the interpreter as input from here on.