
Learn Python the Hard Way - colund
http://learnpythonthehardway.org/book/
======
bluerail
Thank you Zed Shaw.. This is an excellent resource that has helped me to
become what I am today.. I started learning Python using this book and he
really takes time to ensure the readers understand what they are doing.

It may be too silly for you programmers, but almost every beginner programmers
as me would have definitely cam across this resource. This has helped
innumberable and I'm sure it will.. Thanks once again.

~~~
zedshaw
You're welcome. I honestly write the books for people like you, and thankfully
the world of programmers and the world of regular people really doesn't
intersect much.

~~~
pknerd
Thankyou Sir!

I am planning to brush up my SQL knowledge in coming weeks and will read your
stuff. Already enjoyed LPTHW

------
yitchelle
It is interesting that one of the way Zed advocates for learning is to type,
(instead of copy and paste), the code into the computer. That reminds me when
I was cutting my teeth at my introduction to computers. I would get computer
magazines like Compute! and type in the 100s of lines of code that comes with
it. Especially the arcade games listing. I think this method also improve my
debugging skills as I was tracking down the error (usually I did not type in
the code properly or there was a misprint in the magazine).

~~~
jussij
> Zed advocates for learning is to type, (instead of copy and paste)

The copy an paste option is always attractive, as it gives the impression of
writing lots code quickly. But I agree with Zed in that it leads to a false
premiss of being productive.

Coding is all about typing in code, not copy and pasting code.

It's actually quite hard to type in lots of code without generating compiler
errors. But it is quite easy to just copy and paste code without error.

So the copy an paste option leads to a false sense of coding ability.

~~~
tragic
I think the bigger issue is that coding is about knowing what the hell you're
doing. Copying a snippet manually forces you, as a side effect, to read the
code, and read it more slowly than you otherwise would. You notice the limits
of your understanding more quickly, and can try to fill them in.

I didn't learn with Zed's books, but I did (and do) avoid copying and pasting
anything I didn't (don't) understand, and would recommend that approach to any
newbie.

------
snlacks
I didn't start with Zed's stuff, but I checked it out when I was interested in
Python.

For someone like me, it would have been really fun when I was less
experienced. I would have liked the repetitive challenges while I was doing
them, because I would have challenged my self to go through them as fast as a
I could and gamify it (though it wouldn't have been called gamification back
then). It would have got me to memorize things.

His books are different, I appreciate another take on them. I would read and
follow along with his books if they fit my needs now. I've recommended him a
couple times to people I thought would benefit from that style.

As to his personality, I think most people are jerks sometimes, and not jerks
at other times. We all have our issues. :)

Generally, I feel that all the conversations about it much more harmful to the
profession than the original instances being discussed.

~~~
zedshaw
That's a good assessment of the books, and one I put into the introduction.
It's weird because what is great for a beginner with zero knowledge is
incredibly painful for someone who's experienced. I think that's the key with
my book's success and also why a lot of professional programmers seem to
completely dislike it. It's also why I'm very honest and upfront about this
right in the beginning.

------
dsego
If you know anything about programming, skip this book. If you don't know
anything about programming, also skip this book. It gives you drills without
explaining anything. My SO started learning with this book and I could see the
book only caused confusion. She completely misunderstood how functions and
function invocation work. And his way of teaching boolean logic is to memorize
truth tables, wtf?

~~~
brudgers
The pedagogy of _Learn Python th Hard Way_ is called 'Direct Instruction'. It
has been successful for teaching the very rudiments of diverse subjects. It
falls flat once applied to teaching creative intuition or abstract conceptual
reasoning. That's why _Learn Python the Hard Way_ is targeted at beginners.

Page 4 of the Shaw-Hanselman interview transcript discusses direct
instruction.

[http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf](http://s3.amazonaws.com/hanselminutes/hanselminutes_0407.pdf)

Out of curiosity did your SO learn Python and if so what resources worked
particularly well?

~~~
dsego
She is now taking an introductory edX course (Introduction to Computer Science
and Programming Using Python).

~~~
brudgers
Is that the Norvig course where the Python interpreter is in the browser?

~~~
dsego
Nope.

~~~
brudgers
I was thinking of his course at Udacity not Edx.

------
druml
I have been waiting for the completion of Learn C the Hard Way for a while,
BTW.

~~~
zedshaw
Me too, man that book has been an epic slog. I've ended up rewriting it like
10 times but finally have a draft off to the publisher for editing. I'm still
not totally happy with it, but it's the best I could possibly do.

The latest rewrite emphasizes secure coding and defensive programming
practices, algorithms, testing, and how to learn a new programming language,
and simply uses C in as safe a way as possible to do that. Hopefully it's
effective but I still need to sit with students in IRL classes to test that
out better.

~~~
AlexeyBrin
Are you going to update the online version once you publish the printed
version ?

------
koshak
Python 2.5.1

Python 2.6.5

no use of context managers when working with files

no use of format when working with text formatting and output

"Avoid any project that mentions "Python 3""

"Every if-statement must have an else"

no list|dict|generator|set comprehensions.

no idiomatic hints

no gotchas.

Definitely a hard way.

Having learnt wrong leads to hard learning to do right.

~~~
zedshaw
This book is for people who don't know _any_ programming. So let's catalog
your claims in that light:

1\. "no use of context managers when working with files" \- I teach files
early on, before they even know how to make a block. After my book they can
easily learn this.

2\. "no use of format when working with text formatting and output" \- Which
format? At the time I was writing this there were what seemed like 10 changes
to it and how it worked. The % format syntax works all the time, and it's
something found everywhere. Learning it is useful, _and_ doesn't prevent them
from using format later.

3\. "Avoid any project that mentions "Python 3"" \- They should, Python 3 is
not ready and is simply frustrating. Python 2 is on all of their computers
already for many people, so that's the better one for a beginner. Also after
learning 2, they can learn 3 if they need, but if they learn 3, they have to
learn 2.

3\. "Every if-statement must have an else" \- This is for training their
ability to think of the entire set of possible boolean results in an if-
statement. It's _also_ the cause of many logic bugs and you should consider it
as a good way to check your own logic constructs.

4\. "no list|dict|generator|set comprehensions." \- The book is for beginners
who can't even figure out how to run a python script on their own. You think
they'll get comprehensions? That's insane. Later they can easily learn this,
and I think a theme in your comments is that you think once someone reads one
book they are done learning, which is a bizarre idea.

5\. "no idiomatic hints" \- Which idiom would that be? The early Python that's
like JavaWithCamelCase or the new Python that's like c_with_underscores? The
problem with Python idioms is they warp fairly regularly depending on what's
in vogue at the time, so I just teach the simplest thing that seems to be
common among all of them. And again, they will whatever "idiom" you think is
important later when someone like you who thinks they're important yells at
them about it. Brains are not made of stone.

6\. "no gotchas." \-- The book has loads of gotchas, _AND_ I have videos that
go with it where I show people the gotchas, _AND_ there's additional problems
for them to solve at the end of every exercise, _AND_ I encourage them to
break their scripts to see how Python gives them errors.

You would do well to ditch the idea that people cannot relearn things. Maybe
this is holding you back as well, and it's simply false. Heroin and smoking
are "bad habits". Playing a guitar scale wrong is a "bad habit". Whether you
use CamelCase or loads_of_underscores is just easily updated information.

~~~
koshak
1\. using context manager when working with io has two pros: no need to think
about freeing resources, good style.

2\. '{}'.format(). besides, print is a function

3\. python versions you use as a ref in your book were released more than 5
years ago. All major projects have dropped support for them in favor of python
3.3+. Today it is difficult to find a project that doesn't support python3.
There's not so much diff between py3.4 and py2.7. What is frustrating?

4\. Occam's razor and K.I.S.S. tell me keep my stack as small as I can.
Beginners better learn right principles than "easiness". Show them what's
really effective. Programming is 95% mental work, 1% coding, 4%
testing/debugging/optimizing. Teacher cannot inject knowledge into student's
mind, but he can show the right direction and help make first steps.

5\. comprehensions are idiomatic. context managers are idiomatic. Begin from
the beginning. Begin from "import this".

6\. well, yes. Your "they will learn that later" mantra is one of them.

I ditched the idea that learning programming begins with choosing a language
and learning its basics. Instead you go learn KISS, DRY, YAGNI, etc., history
of programming languages, stateful vs stateless, and learn this by practice,
by exercise, just like playing the guitar. You begin with handling the
instrument the right way and learning basics of music theory and once you get
the idea of pentatonic scale and bebop you can go practice it, not vice versa.
Well, you can play bebop in pentatonic and not be aware of what you're doing,
but understanding the underlying theory and alternative approaches is the key
to learning more complex things and discovering new horizons.

Relearning is a bad habit. Reusing your knowledge and expereince is a good
one.

------
cjf4
Having actually used this as a self learning tool, my feelings were mixed. On
one hand, I think it's organized and clear. On the other, I found it's drill
approach to be ineffective for me.

I think reps are really good for something that uses muscle memory, like
shooting 3s or dicing an onion. However, I found for learning programming, I
got a lot more mileage out of teaching methods that have set up a solvable
problem, point you in the right direction, but leave it to me to create a
solution.

------
ghost91
And still not using python3.X …

~~~
volent
"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.

~~~
ptx
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](https://www.youtube.com/watch?v=sgHbC6udIqc)

~~~
dr_zoidberg
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.

~~~
ptx
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")

------
brudgers
Scott Hanselman's great podcast interview with Zed Shaw:

[http://hanselminutes.com/407/learning-code-the-hard-way-
with...](http://hanselminutes.com/407/learning-code-the-hard-way-with-zed-
shaw)

------
arafa
I went through this whole class when it was linked here a couple of months
back and really enjoyed it. I'm a self-taught programmer that needed updates
on some modern concepts and a refresher on some other stuff, plus a bit of
help with Python syntax. If you're like me (or a beginner) it's great. Thanks
Zed.

------
thebouv
I have no idea who Zed Shaw is. I've always wanted to know more about Python.
Might give it an unbiased read through.

~~~
Johnny_Brahms
If you want to see some really nice python, look at his "lamson" project. It's
really nice.

------
cdnsteve
Loved the "A Warning for the Smarties" part.

------
ianamartin
Ummm, I don't understand all the dislike. For someone with my background, this
was absolutely perfect. It's one of the very first things I read when I
decided I wanted to learn Python. Fast forward several years, and now writing
Python code is what I do for a living. I could not be happier.

I was a violinist, and Zed Shaw's way of teaching the basics completely
resonated with me.

Thank you, Zed.

------
dmkmz
Hello Zed. I didn't actually read whole LPTHW, but LCTHW helped me a lot. I
recommended LPTHW to some friends of mine, who were interesting in programming
but had no experience at all. Few years later and they are doing programming
for living. I personally think it's a good source for a newbie to start with.
Keep going with your job and thanks.

------
pknerd
Sorry for being OT but I would request Zedshaw to write next book about Go
Language.

------
napolux
So, is it good or not? :D

~~~
dagw
If you're new to programming, it's pretty good. If you're an experienced
programmer looking to pick up python, then it is very slow going and takes a
while before it gets anywhere interesting.

Basically it should really be called Learn Programming The Hard Way Using
Python

~~~
M8
But then it will be confusing, people will assume that scripting is the same
thing as programming.

~~~
toolz
Probably because scripting is programming.

------
munchhausen
So I'm scrolling through this comment section, thinking, "Are we ever going to
talk about the book or what?".

This thread is proof that programmer types need their share of celebrity
gossip as much as anyone :)

"That Zed Shaw. He's abrasive, but is he too abrasive? Tune in to our panel
discussion to find out!"

~~~
qzcx
Right? I came to the comment section to post something I found funny in the
introduction... but I'm afraid people will get offended by it now.

"If you are reading this book and flipping out at every third sentence because
you feel I'm insulting your intelligence, then I have three points of advice
for you:

1.Stop reading my book. I didn't write it for you. I wrote it for people who
don't already know everything.

2.Empty before you fill. You will have a hard time learning from someone with
more knowledge if you already know everything.

3.Go learn Lisp. I hear people who know everything really like Lisp."

------
las_cases
Wow, how come Zed Shaw manages to attract so much hate? I have found his
series to be absolutely delightful. Anytime something about him appears on HN
I can be sure there will be users with ad hominem attacks like this:

"> is this a joke?

No, just written by Zed Shaw. Honest mistake though."

How about you let go of the hate and embrace some love instead for the work
this man has put forth?

LE: For advanced Python you can read his code from the Lamson project. I am
sure there are many other coders out there who are just as talented as he is
but he takes the time to comment his code and also has a style of clarity so
to speak. Thank you Mr. Shaw for your work and thank you to all of the
amazing, talented coders out there who gave me confidence and helped me to
learn.

~~~
cheetos
You should consider if there may be a good reason why he attracts so much
hate.

I have found him to be contrarian and rude for the sake of being contrarian
and rude.

To me, his behavior represents the worst of the archetypal 'rockstar'
programmers I have worked with -- perhaps more skilled than the average, but
full of himself, unreasonably mean and impossible to collaborate or work with.
I have watched this kind of attitude destroy teams and companies and I prefer
not to condone it.

There are plenty of people much more talented than him who are capable of
providing feedback without seemingly delighting in being an asshole.

~~~
knowtheory
Keep on hatin'. Zed's just going to keep writing books that help people, and
your impression of him will merely drown beneath the tides of people who
benefit from all the work he's put into FOSS & teaching others.

I don't agree w/ Zed on everything, but i have benefitted from his work for
literally a decade now: mongrel; his early writing on why programmers should
learn statistics; his writings on the types of collaboration/projects
programmers are involved in; Learn C The Hard Way; his various talks.

~~~
ritchiea
It's certainly possible to both be rude and write books that help people. The
two behaviors are not mutually exclusive. I think it's completely reasonable
to laud Zed for his efforts to teach while questioning his manner.

~~~
knowtheory
Except this is a post about his book and his teaching? But here we are
dedicating all this time to rehashing all this stuff that happened years ago
with people who obviously weren't there at the time.

------
Psion7
Why is this at the top of HN? Didn't the 3rd edition come out ages ago? What
exactly is new?

~~~
piqufoh
HN has a ranking system which differs to reddit etc. You'll be seeing what's
"hot" as ranked by the algorithm

[http://amix.dk/blog/post/19574](http://amix.dk/blog/post/19574)

If you're looking for what's popular, check out

[https://news.ycombinator.com/best](https://news.ycombinator.com/best)

------
dsego
ah, Python, the language where you have to learn for in range() before even
knowing functions or lists. Just memorize this, we'll explain it later...

~~~
wz1000
To be fair, this occurs with most mainstream languages.

I'm pretty sure a beginner has no idea what "public static void main(String[]
args)" means.

------
QuercusMax
After reading the Intro and first chapter - is this a joke?

~~~
piqufoh
Did you read the _whole_ intro?

> Sometimes people who already know a programming language will read this book
> and feel I'm insulting them.

~~~
QuercusMax
I saw that part. Still triggered my "maybe and elaborate troll" detector. He
doesn't explain _why_ he's doing it this way.

~~~
JanezStupar
You are triggering my "maybe an elaborate troll" detector.

Especially as the GP has already referred to the intro, which you have
supposedly already read.

So let me point it out for you again:
[http://learnpythonthehardway.org/book/intro.html](http://learnpythonthehardway.org/book/intro.html)

He goes into great detail arguing why he thinks this is one of the best ways
to learn something completely new quickly and efficiently.

~~~
QuercusMax
The first lesson literally consists of "run python interpreter, then quit".

How is this a useful way to approach things? He compares it to learning to
play guitar - if my first guitar lesson consisted of "Open your guitar case.
Take out the guitar. Put it back.", I'd ask for my money back!

~~~
astine
I tried teaching my little brother to program using the Ruby version of this
book. The lessons were really basic but he still struggled.

If the first lesson in an introductory guitar book was how to properly handle
a guitar, I would not be surprised at all. In fact, I know from experience
with other instruments that that would be entirely normal.

