Hacker News new | ask | show | jobs
by ghost91 4099 days ago
And still not using python3.X …
3 comments

"A programmer may try to get you to install Python 3 and learn that. Say, "When all of the Python code on your computer is Python 3, then I'll try to learn it." That should keep them busy for about 10 years. I repeat, do not use Python 3. Python 3 is not used very much, and if you learn Python 2 you can easily learn Python 3 when you need it. If you learn Python 3 then you'll still have to learn Python 2 to get anything done. Just learn Python 2 and ignore people saying Python 3 is the future."

I don't think it is useful for a beginner to start with python3.

Python 3 is useful for a beginner to start with because they don't have to learn the deprecated cruft that Python 2 preserves for compatibility. If they just learn the Python 3 way of doing things, it generally works in both 2 and 3.

In his explanation of classes he has several paragraphs about old-style vs. new-style classes, ending it with:

  "Just completely ignore the idea of old style versus
  new style classes and assume that Python always requires
  (object) when you make a class. Save your brain power for
  something important."
Python 3 only has new-style classes, so the entire explanation could have been left out, allowing the beginner to, as he recommends, focus on more interesting things.

Another example is his advice, in exercise 11, to avoid the input() function because of its security problems. Python 3 doesn't have that function, so the beginner doesn't have to remember to avoid it.

And of course, there's Unicode, which this book seems to completely ignore. A beginner starting with Python 3 has to learn the "Unicode sandwich" approach[1], which applies very well to Python 2 code as well. But someone starting with Python 2 can easily be confused about the concept (because the language is confused) and will have a hard time getting things to work correctly. For example, the book recommends that people "from another country" set their source encoding to UTF-8 – good luck printing things on Windows.

[1] https://www.youtube.com/watch?v=sgHbC6udIqc

No one's saying that Python 3 doesn't improve on Python 2 in significant and tangible ways. The key phrase is "If you learn Python 3 then you'll still have to learn Python 2 to get anything done" which is absolutely true in my experience.[1] This is because as soon as you hit a single dependency that doesn't support Python 3, you have to switch to Python 2. And there are still a good number of important modules that are Python 2 only. (And no, reimplementing the functionality of dependency oneself is not an option for a beginning programmer.) And even if all the modules you need right now are available for Python 3, you might find later that the new feature you want to implement in an existing program requires a Python2-only module. No matter how great Python 3 is, and how much we all wish we could switch to it, we can't just will all our dependencies to add support for it.

[1] Obviously your experience may vary depending on which modules are considered essential for your work.

I'm from "another country" and I always asumed all the characters that couldn't be printed on screen by Python were cmd.exe's (and powershell) fault for not handling Unicode correctly, not a Python "error" per se.

Also, all my Python sources are set to UTF-8 and I never had any problem in Windows. Notepad.exe gives you the encoding option when you save a file, and every sensible text editor/IDE gives you encoding and line feed options.

So what would be the problem with Zed's tip? Have you ever tried to run a Python script with special characters? The interpreter dies instantly with an encoding error. It's easier to set the encoding to UTF-8 and get the program running than parse the whole thing checking whether you used a special character in the comments -- which shouldn't affect program execution, but hey!. Also, this way you can write meaningful comments in your native language without worrying if it'll kill the interpreter right away.

The problem is that the Windows commandline, legacy Windows programs and modern Unix systems all use different encodings, so any particular string of bytes (representing non-ASCII text) will only be correct on one of them.

For example, let's say our Other Country is a Western European country. The encoding for non-Unicode Win32 programs will be Windows-1251 (more or less ISO 8859-1) and the encoding for MS-DOS programs and the commandline will be codepage 850.

In this scenario, this Python 2 program (saved as UTF-8):

  #-*- coding: utf-8 -*-
  print "ångström"
will print the wrong thing – "├Ñngstr├Âm" if you run it from the commandline, and "Ã¥ngström" in a more Windowsy context (e.g. if you're writing it to a file and reading it in Notepad).

To make it correct, you can apply the Unicode sandwich approach:

1) Know the input encoding and decode from that to Unicode.

2) Process the text as Unicode.

3) Know the output encoding and encode into that encoding on output.

In other words, making it a Unicode string will transform the text from whatever encoding you chose to write the file in to whatever encoding your terminal happens to use, so this program will always (if the system is correctly configured) print the right thing:

  #-*- coding: utf-8 -*-
  print u"ångström"
In Python 3, UTF-8 source encoding and Unicode strings are the default, so the correct program becomes simply:

  print("ångström")
The problem isn't extended characters in your Python script, it's how your Python script handles extended character data. Scripts written in Python 2 that ignore the existence of Unicode won't always do the right thing when they encounter non-ASCII strings in the wild.
Nearly all packages are ported to python3. There are still some bigger projects missing, but these are exceptions and not the norm.

Python3 simplifies many aspects of the language, for example handling of bytes and handling different encodings. In my day to day use I don't want to miss these features.

Many interesting features where added in 3, like yield from, more powerful generator syntax and the libraries multiprocessing and pathlib.

Well, this quote is a little pessimistic because now almost everything is either Python 3 compatible or has been replaced with something that is and it's only been 7 years. :P

Even NumPy and SciPy work on Python 3 now, and it's not like there are massive differences between Py2 and Py3 anyway, so generally speaking it shouldn't be hard for a noob to revert to Py2 if it becomes inexplicably necessary.

It's time. All new code should be in Python 3.

Call me when I can get system packages for all of these libraries (particularly those with shared library dependencies) in Python3.

It will happen someday, but not yet.

I can't find a publication date for the first version, but since the second edition [was published in 2010](http://webcache.googleusercontent.com/search?q=cache:eW9X2nO...) I suspect it's now been nearly 10 years since that statement was written.
And still true.
yeaaah, no.
Yeah, check pip stats.
That nearly all good intros to Python for non-programmers insist on teaching only Python 2.x, because Python 2.x is what's used in lots of advanced programs and production code, is an attitude that I've found very unhelpful as a beginner.

True beginners don't need to use numpy and run a bunch of production-ready libraries. They first need to learn what libraries ARE and the basics of using them. Besides, numpy &c. can already run on Python3, how much further will they be along in 1-3 years? Most simple Python3 programs work fine in Python 2.7.9 with little wrangling, and it's not hard to keep two installs of Python.

"Learn Python" right now means "learn both", only many introductory tutorials will refuse to teach both. Instead they'll compound your frustration by making you learn the intricacies of Python 2's print statement instead of print().

It is very useful for a beginner to start with python3, as python3 makes the difference between strings and byte sequences much clearer.

The majority of python code on my computer is now python 3.

If you're worried about the distinction between strings and byte sequences, you're thinking about a different sort of "beginner".
A beginner will want to read and write files pretty early on. In Python 2 it's very easy to e.g. ignore that you need to pass the 'b' option for reading binary files and write scripts that seem to work, and then silently corrupt data when run on windows. Which is not a good experience.
it is. regardless of python3 progress. But nowadays it's easier to name the project that does not support python3 http://py3readiness.org/
Wouldn't this argument preclude using anything new, ever? Don't use C++14 until all of your code is converted to use it. Don't touch ES6 until you throw out your legacy JavaScript. Some of these programs haven't been updated to use Linux-specific features, so let's all stick to UNIX System V.

If anyone is best in the position to take up the bleeding edge with no thought to backwards compatibility, it's the people just starting out. They're the ones who, by definition, don't have legacy code to maintain.

I have my main work database / Django project in Python 2.

I have a few smaller projects I have started since then - I used Python 3.

There are very few noticeable differences. Why would you not start with a more up to date version. Unless there are specific packages you need or expect to need that are not supported I would say Python 3 makes more sense.

I've been using Python 3 for stuff and pretty much everything is there on Python 3. (django, flask, pillow instead of PIL, etc)
I have to serve the student's needs before any in the community, and there's a very practical reason for going with Python2:

The vast majority of code out there is in Py2, so if someone learns Py2 first, they can start coding and doing stuff right now. If they stumble onto a need for Py3 later, then they would have the skill to learn Py3 from the tutorial and other books.

If they learn Py3 first, then immediately they have to learn Py2 because there's simply too much code out there that uses it. This will frustrate beginners as the next thing they need to do after my book is start using Python to make things.

When the situation changes, and not just because the Python leaders say it does, then I'll update the book. Honestly though, I think Go, Rust, Nim, and Clojure have a better chance at widespread adoption than Python3 at this point.

Incidentally, the mistake that the Python3 project made was to not use a virtual machine that could run both 2 and 3 byte code. If I can run tons of languages on my CPU, the JVM, and the .NET CLR, then Python3 could have run both 2 and 3. I predict that to get people on the new version of Python they will have to make Python4 and have it run 2,3 and 4 seamlessly so that it won't matter how much code is out there in any version of the language.

Just my .02 on that topic.

Is anything? I've recently decided to start learning Python and started with the assumption that Python 3 would self-evidently be the sensible thing to do.

I tried that for about a week before discovering that about 90% of the libraries that I wanted to play with, and 90% of the tutorials and StackOverflow answers that I found were 2.7-specific.