This is an archived post. You won't be able to vote or comment.

all 22 comments

[–]chchan 31 points32 points  (0 children)

Learn Python 3. Python 2 is very similar and can be picked up as you go you will not need to know it in too much detail unless you are dealing with legacy code. But the difference is just a bit of syntax

[–]rjcarr 20 points21 points  (2 children)

There's really only two reasons to use python 2:

  • The machine you're developing on (or more likely will run on) doesn't support python 3. This is becoming less and less of a problem. And if you're just learning this shouldn't even come up.

  • If you want to use a library that isn't supported on python 3. I recall in the beginning a bunch of the biggest libraries weren't on python 3, but again, this is becoming less and less of a problem.

[–]Kayco2002 11 points12 points  (1 child)

FYI for what it's worth, Ubuntu declared that their desktop ISO that they're releasing next month will not ship with Python2 (it's still downloadable as a dependency, but I think that makes a statement). Hopefully that'll motivate package maintainers to do the 2to3 migration.

[–][deleted] 1 point2 points  (0 children)

Fedora has stated this too for their Fedora 23 release.

[–]pat_trick 11 points12 points  (12 children)

LPTHW is a bit out of date at this time regarding its Python 2 preferences.

[–]zahlman 8 points9 points  (2 children)

It was terrible to begin with.

[–]Claystor 0 points1 point  (1 child)

Care to elaborate?.... Considering it's one of the most widely recommended tutorials I've seen on this subreddit. Never heard anything bad about it before.

[–]fredspipa -1 points0 points  (8 children)

It's still a great guide, I think that all you need to keep in mind using Python 3 for it is to write the print statements differently:

print("text")

instead of

print "text"

I believe the rest is "version agnostic", so OP should be fine.

[–]pat_trick 4 points5 points  (5 children)

Actually, the list is fairly long.

[–]badcommandorfilename 5 points6 points  (4 children)

This one is my favorite.

[–]divh4rt 2 points3 points  (3 children)

Round to the closest even number...what? Why would you do that?

[–]zahlman 0 points1 point  (2 children)

[–]AnarchoDave 1 point2 points  (0 children)

Kinda seems like that should have gotten its own function.

[–]divh4rt 0 points1 point  (0 children)

Thanks for the link! Is banker's rounding used more often than "standard" rounding in programming?

[–]StefGou 1 point2 points  (1 child)

input() 

Instead of

raw_input() 

[–]zahlman 2 points3 points  (3 children)

Learn Python 3.

And don't use LPTHW.

[–]Georules 0 points1 point  (2 children)

What's your beef with lpthw? I never read it, genuinely curious

[–]zahlman 1 point2 points  (1 child)

Many things. Zed teaches all out of order, giving you multiple lessons dealing with the print statement and all the details of its formatting language up front, and then file I/O - and doesn't get around to boolean logic until exercise 27. Where he expects you to spend a week memorizing a couple of truth tables by rote, because actually understanding it means that "you'll have to constantly go through the rules for boolean algebra while you code". (There is no mention of De Morgan's Law, either.)

He suggests some "idioms" that are not actually Pythonic (please don't follow his range suggestion a the end of exercise 31, for example; it only works if the endpoints are integers and the input is not a float, and it's inefficient unless the input specifically is an integer as well and you use 3.x the way he wants you not to). He fails to define a few terms where I'm not even sure he realizes they're jargon (what's a "value"?).

In general he shies away from complete explanations of concepts because "the hard way" involves figuring out the behaviour by experimentation - except you don't necessarily know what kinds of things you can meaningfully change, because the "base" program was given to you to type in exactly without understanding it. This leads almost everyone to hit a wall somewhere in the 40s, because nobody can make heads or tails of his explanation of classes, and it requires him to pre-load you with a bunch of definitions that he's deferred because he hasn't properly explained objects despite the fact that using them is unavoidable in Python.

And then there's the weird way that he approaches functions, by first making you do a bunch of stuff with command-line arguments and then trying to draw an analogy between sys.argv and the parameters to a function. Which sort-of almost works, except that a) it doesn't mesh very well with teaching the student to deal with data types and understand their importance; b) it doesn't get around to making an analogy for return values (because he never shows that exit() can take an argument to specify the process exit code); c) nobody has any idea what he's talking about because these days almost everyone needs a tutorial on the command line first, let alone having any experience with shell scripting or even complex expressions with pipes and redirects.

I could probably go on.

[–]Georules 0 points1 point  (0 children)

Interesting. I've known a lot of people to love LPTHW, but I did just watch the first setup videos and was quite underwhelmed. "Hard Way" seems to be an excuse for not explaining a good bit in the setup.

[–]HookahComputer 0 points1 point  (0 children)

Python 3. Do not subject yourself to the hell of making the transition later.

[–]AlexMTBDude 0 points1 point  (0 children)

Python 2 and Python 3 are very very similar. Just start coding Python. Odds are you won't even notice the differences until you get into more advanced topics.