《Learn Python The Hard Way, 1st Edition》的原文摘录

  • 我从事编程已经太长时间,长到对我来说编程已经是非常乏味的事情了。我写这 本书的时候,已经懂得大约 20 种编程语言,而且可以在大约一天或者一个星 期内学会一门编程语言(取决于这门语言有多古怪)。现在对我来说编程这件事情 已经很无聊,已经谈不上什么兴趣了。当然这不是说编程本身是一件无聊的事情, 也不是说你以后也一定会这样觉得,这只是我个人在当前的感觉而已。 在这么久的旅程下来我的体会是:编程语言这东西并不重要,重要的是你用这些 语言做的事情。事实上我一直知道这一点,不过以前我会周期性地被各种编程语 言分神而忘记了这一点。现在我是永远不会忘记这一点了,你也不应该忘记这一 点。 你学到和用到的编程语言并不重要。不要被围绕某一种语言的宗教把你扯进去, 这只会让你忘掉了语言的真正目的,也就是作为你的工具来实现有趣的事情。 编程作为一项智力活动,是唯一一种能让你创建交互式艺术的艺术形式。你可以 创建项目让别人使用,而且你可以间接地和使用者沟通。没有其他的艺术形式能 做到如此程度的交互性。电影领着观众走向一个方向,绘画是不会动的。而代码 却是双向互动的。 编程作为一项职业只是一般般有趣而已。编程可能是一份好工作,但如果你想赚 更多的钱而且过得更快乐,你其实开一间快餐分店就可以了。你最好的选择是将 你的编程技术作为你其他职业的秘密武器。 技术公司里边会编程的人多到一毛钱一打,根本得不到什么尊敬。而在生物学、 医药学、政府部门、社会学、物理学、数学等行业领域从事编程的人就能得到足 够的尊敬,而且你可以使用这项技能在这些领域做出令人惊异的成就。 当然,所有的这些建议都是没啥意义的。如果你跟着这本书学习写软件而且觉得 很喜欢这件事情的话,那你完全可以将其当作一门职业去追求。你应该继续深入 拓展这个近五十年来极少有人探索过的奇异而美妙的智力工作领域。若能从中得 到乐趣当然就更好了。 最后我要说的是... (查看原文)
    九识澪 4回复 17赞 2017-07-08 22:41:33
    —— 引自章节:老程序员的建议
  • Rules For If-Statements 1.Every if-statement must have an else. 2.If this else should never be run because it doesn't make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors. 3.Never nest if-statements more than 2 deep and always try to do them 1 deep. This means if you put an if in an if then you should be looking to move that second if into another function. 4.Treat if-statements like paragraphs, where each if,elif,else grouping is like a set of sentences. Put blank lines before and after. 5.Your boolean tests should be simple. If they are complex, move their calculations to variables earlier in your function and use a good name for the variable. Rules For Loops 1.Use a while-loo... (查看原文)
    爱乐的陈 1赞 2012-03-16 15:19:41
    —— 引自章节:Exercise 36: Designing and Deb
  • If they like control and have a huge beard, they'll tell you to install Linux. (查看原文)
    陈卤蛋 1回复 2011-09-18 20:53:51
    —— 引自章节:exercise 0
  • Hit CTRL-D (^D) and get out of python. > mkdir mystuff > cd mystuff > dir (查看原文)
    爱乐的陈 2012-03-06 22:12:26
    —— 引自章节:Exercise 0: The Setup
  • From now on, when you make mistakes write down on a piece of paper what kind of mistake you made. When you go to the next exercise, look at the last mistakes you made and try not to make them in this new one. (查看原文)
    爱乐的陈 2012-03-08 19:22:17
    —— 引自章节:Exercise 7: More Printing
  • If you're on Windows try python -m pydoc raw_input instead. Get out of pydoc by typing q to quit. (查看原文)
    爱乐的陈 2012-03-09 16:17:22
    —— 引自章节:Exercise 12: Prompting People
  • The argv is the "argument variable", a very standard name in programming, that you will find used in many other languages. This variable holds the arguments you pass to your Python script when you run it. In the exercises you will get to play with this more and see what happens. Line 3 "unpacks" argv so that, rather than holding all the arguments, it gets assigned to four variables you can work with: script, first, second, and third. This may look strange, but "unpack" is probably the best word to describe what it does. It just says, "Take whatever is in argv, unpack it, and assign it to all of these variables on the left in order." (查看原文)
    爱乐的陈 2012-03-09 16:32:26
    —— 引自章节:Exercise 13: Parameters, Unpac
  • You should immediately notice that we import another handy command named exists. This returns True if a file exists, based on its name in a string as an argument. It returns False if not. Did you see that trick I did with cat? It only works on Linux or OSX, on Windows use type to do the same thing. (查看原文)
    爱乐的陈 2012-03-12 20:27:56
    —— 引自章节:Exercise 17: More Files
  • Functions do three things: 1.They name pieces of code the way variables name strings and numbers. 2.They take arguments the way your scripts take argv. 3.Using #1 and #2 they let you make your own "mini scripts" or "tiny commands". You can create a function by using the word def in Python. (查看原文)
    爱乐的陈 2012-03-12 20:59:32
    —— 引自章节:Exercise 18: Names, Variables,
  • This shows all different ways we're able to give our function cheese_and_crackers the values it needs to print them. We can give it straight numbers. We can give it variables. We can give it math. We can even combine math and variables. (查看原文)
    爱乐的陈 2012-03-12 21:51:47
    —— 引自章节:Exercise 19: Functions And Var
  • Try doing this: help(ex25) and also help(ex25.break_words). Notice how you get help for your module, and how the help is those odd """ strings you put after each function in ex25? Those special strings are called documentation comments and we'll be seeing more of them. (查看原文)
    爱乐的陈 2012-03-13 20:54:37
    —— 引自章节:Exercise 25: Even More Practic
  • A colon at the end of a line is how you tell Python you are going to create a new "block" of code, and then indenting 4 spaces tells Python what lines of code are in that block. (查看原文)
    爱乐的陈 2012-03-14 19:08:23
    —— 引自章节:Exercise 30: Else And If
  • To avoid these problems, there's some rules to follow: 1.Make sure that you use while-loops sparingly. Usually a for-loop is better. 2.Review your while statements and make sure that the thing you are testing will become False at some point. 3.When in doubt, print out your test variable at the top and bottom of the while-loop to see what it's doing. If at any time that you are doing this it goes crazy (it probably will), just hold down CTRL and hit c (CTRL-c) and the program will abort. (查看原文)
    爱乐的陈 2012-03-15 14:23:00
    —— 引自章节:Exercise 33: While Loops
  • When you write comments, describe why you are doing what you are doing. The code already says how, but why you did things the way you did is more important. (查看原文)
    爱乐的陈 2012-03-18 18:39:16
    —— 引自章节:Exercise 44: Evaluating Your G
  • Explain why the 4.0 is used instead of just 4. (查看原文)
    wangv 2012-11-20 22:16:45
    —— 引自第22页
  • 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: - Stop reading my book. I didn't write it for you. I wrote it for people who don't already know everything. - Empty before you fill. You will have a hard time learning from someone with more knowledge if you already know everything. - Go learn Lisp. I hear people who know everything really like Lisp. For everyone else who's here to learn, just read everything as if I'm smiling and I have a mischievous little twinkle in my eye. (查看原文)
    ss 3回复 2013-04-17 12:12:44
    —— 引自章节:Intro
  • 1.逆向阅读,在每一行的上面加一行注解。 2.倒着朗读出来,找出自己的错误。 3.从现在开始,把你的错误记录下来,写在一张纸上。 4.在开始下一节习题时,阅读一遍你记录下来的错误,并且尽量避免在下个练习中再犯同样的错误。 5.记住,每个人都会犯错误。程序员和魔术师一样,他们希望大家认为他们从不犯错,不过这只是表象而已,他们每时每刻都在犯错。 (查看原文)
    [已注销] 2013-05-18 21:35:13
    —— 引自章节:习题 7
  • This book's job is to teach you the three most essential skills that a beginning programmer needs to know: reading and writing, attention to detail, and spotting differences. (查看原文)
    MAHONE 2014-02-06 14:05:38
    —— 引自章节:Introduction
  • Study Drills Find out if you were right about what the # character does and make sure you know what it's called (octothorpe or pound character). Take your ex2.py file and review each line going backward. Start at the last line, and check each word in reverse against what you should have typed. Did you find more mistakes? Fix them. Read what you typed above out loud, including saying each character by its name. Did you find more mistakes? Fix them. Why do I have to read code backward? It's a trick to make your brain not attach meaning to each part of the code, and doing that makes you process each piece exactly. This catches errors and is a handy error-checking technique. (查看原文)
    多丽耶特 2014-08-19 02:12:53
    —— 引自章节:Excercise 2: Comments and Poun
  • Keywords KEYWORD DESCRIPTION EXAMPLE and Logical and. True and False == False as Part of the with-as statement. with X as Y: pass assert Assert (ensure) that something is true. assert False, "Error!" break Stop this loop right now. while True: break class Define a class. class Person(object) continue Don't process more of the loop, do it again. while True: continue def Define a function. def X(): pass del Delete from dictionary. del X[Y] elif Else if condition. if: X; elif: Y; else: J else Else condition. if: X; elif: Y; else: J except If an exception happens, do this. except ValueError, e: print e exec Run a string as Python. exec 'print "hello"' finally Exceptions or not, finally do this no matter what. finally: pass for Loop over a collection of things. for X in Y: pass from Importing ... (查看原文)
    mhsj 2015-01-29 14:10:05
    —— 引自章节:全书笔记
<前页 1 2 后页>