From apprentice to guru

I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solutions and also with the semantics of the language that allows such a natural flow from thoughts to workable code.

What I would like to know is your answer to a kind of question I have seldom seen in this or other forums. This question seems central to me for anyone on the path to Python improvement but who wonders what his next steps should be.

Let me sum up what I do NOT want to ask first ;)

  • I don't want to know how to QUICKLY learn Python
  • Nor do I want to find out the best way to get acquainted with the language
  • Finally, I don't want to know a 'one trick that does it all' approach.
  • What I do want to know your opinion about, is:

    What are the steps YOU would recommend to a Python journeyman, from apprenticeship to guru status (feel free to stop wherever your expertise dictates it), in order that one IMPROVES CONSTANTLY, becoming a better and better Python coder, one step at a time. Some of the people on SO almost seem worthy of worship for their Python prowess, please enlighten us :)

    The kind of answers I would enjoy (but feel free to surprise the readership :P ), is formatted more or less like this:

  • Read this (eg: python tutorial), pay attention to that kind of details
  • Code for so manytime/problems/lines of code
  • Then, read this (eg: this or that book), but this time, pay attention to this
  • Tackle a few real-life problems
  • Then, proceed to reading Y.
  • Be sure to grasp these concepts
  • Code for X time
  • Come back to such and such basics or move further to...
  • (you get the point :)
  • I really care about knowing your opinion on what exactly one should pay attention to, at various stages, in order to progress CONSTANTLY (with due efforts, of course). If you come from a specific field of expertise, discuss the path you see as appropriate in this field.

    EDIT: Thanks to your great input, I'm back on the Python improvement track! I really appreciate!


    I thought the process of Python mastery went something like:

  • Discover list comprehensions
  • Discover generators
  • Incorporate map, reduce, filter, iter, range, xrange often into your code
  • Discover Decorators
  • Write recursive functions, a lot
  • Discover itertools and functools
  • Read Real World Haskell (read free online)
  • Rewrite all your old Python code with tons of higher order functions, recursion, and whatnot.
  • Annoy your cubicle mates every time they present you with a Python class. Claim it could be "better" implemented as a dictionary plus some functions. Embrace functional programming.
  • Rediscover the Strategy pattern and then all those things from imperative code you tried so hard to forget after Haskell.
  • Find a balance.

  • One good way to further your Python knowledge is to dig into the source code of the libraries, platforms, and frameworks you use already.

    For example if you're building a site on Django, many questions that might stump you can be answered by looking at how Django implements the feature in question.

    This way you'll continue to pick up new idioms, coding styles, and Python tricks . (Some will be good and some will be bad.)

    And when you see something Pythony that you don't understand in the source, hop over to the #python IRC channel and you'll find plenty of "language lawyers" happy to explain.

    An accumulation of these little clarifications over years leads to a much deeper understanding of the language and all of its ins and outs.


    Understand (more deeply) Python's data types and their roles with regards to memory mgmt

    As some of you in the community are aware, I teach Python courses, the most popular ones being the comprehensive Intro+Intermediate course as well as an "advanced" course which introduces a variety of areas of application development.

    Quite often, I get asked a question quite similar to, "Should I take your intro or advanced course? I've already been programming Python for 1-2 years, and I think the intro one is too simple for me so I'd like to jump straight to the advanced... which course would you recommend?"

    To answer their question, I probe to see how strong they are in this area -- not that it's really the best way to measure whether they're ready for any advanced course, but to see how well their basic knowledge is of Python's objects and memory model, which is a cause of many Python bugs written by those who are not only beginners but those who have gone beyond that.

    To do this, I point them at this simple 2-part quiz question: Ex1:x = 42; Y = X; X + = 1; print x,y Ex2:x = [1,2,3]; y = x; x [0] = 4; print x,y

    Many times, they are able to get the output, but the why is more difficult and much more important of an response... I would weigh the output as 20% of the answer while the "why" gets 80% credit. If they can't get the why, regardless how Python experience they have, I will always steer people to the comprehensive intro+intermediate course because I spend one lecture on objects and memory management to the point where you should be able to answer with the output and the why with sufficient confidence. (Just because you know Python's syntax after 1-2 years doesn't make you ready to move beyond a "beginner" label until you have a much better understanding as far as how Python works under the covers.)

    A succeeding inquiry requiring a similar answer is even tougher, eg,

    Example 3

    x = ['foo', [1,2,3], 10.4]
    y = list(x) # or x[:]
    y[0] = 'fooooooo'
    y[1][0] = 4
    print x
    print y
    

    The next topics I recommend are to understanding reference counting well, learning what "interning" means (but not necessarily using it), learning about shallow and deep copies (as in Example 3 above), and finally, the interrelationships between the various types and constructs in the language, ie lists vs. tuples, dicts vs. sets, list comprehensions vs. generator expressions, iterators vs. generators, etc.; however all those other suggestions are another post for another time. Hope this helps in the meantime! :-)

    ps. I agree with the other responses for getting more intimate with introspection as well as studying other projects' source code and add a strong "+1" to both suggestions!

    pps. Great question BTW. I wish I was smart enough in the beginning to have asked something like this, but that was a long time ago, and now I'm trying to help others with my many years of full-time Python programming!!

    链接地址: http://www.djcxy.com/p/7410.html

    上一篇: Python的隐藏功能

    下一篇: 从徒弟到专家