我学习、工作和使用Python已经有一年半的时间了。作为一名慢慢转向生物信息学的生物学家,这种语言一直是我在实验室所做的所有主要贡献的核心。我或多或少爱上了Python让我表达美丽的解决方案的方式,也爱上了这种语言的语义,它允许从思想到可行的代码的自然流动。

有一个问题,我很少在这里或其他论坛看到,我想听听你的回答。在我看来,这个问题对于任何走在Python改进道路上的人来说都很重要,但他不知道下一步应该做什么。

让我先总结一下我不想问的问题;)

我不想知道如何快速学习Python 我也不想找出熟悉这门语言的最佳方法 最后,我不想知道“一个技巧可以解决所有问题”的方法。

我想知道你的意见是:

从学徒到大师,你会向Python熟练者推荐哪些步骤,以便一个人不断提高,成为一个越来越好的Python程序员,一次一步。SO上的一些人几乎因为他们的Python能力而值得崇拜,请启发我们:)

我喜欢的那种回答(但请随意给读者惊喜:P),格式或多或少是这样的:

阅读这个(例如:python教程),注意那种细节 这么多时间/问题/行代码的代码 然后,读这本(例如:这本或那本书),但这次,注意这本 解决一些现实生活中的问题 然后,继续读取Y。 一定要掌握这些概念 X时间的代码 回到这样那样的基础或进一步讨论…… (你懂的)

我真的很想知道你对一个人在不同阶段应该注意什么问题的看法,以便不断进步(当然,要付出适当的努力)。如果你来自一个特定的专业领域,讨论一下你认为适合这个领域的道路。

编辑:感谢您的大力投入,我又回到了Python改进的轨道上!非常感谢!


当前回答

你看过《用Python编程生物信息学》这本书吗?看来你是焦点小组的一员。

其他回答

我第一次自学python是在一个夏天的时候,只是在python网站上做教程(遗憾的是,我似乎再也找不到它了,所以我不能发布链接)。

后来,在我大学一年级的课程中,有人教了我python。在接下来的夏天,我用PythonChallenge和谷歌Code Jam中的问题进行了练习。 从算法的角度,从学习Python可以做什么以及如何操作它来充分利用Python的角度,解决这些问题是有帮助的。

出于类似的原因,我听说code golf也可以,但我自己从未尝试过。

(更深入地)理解Python的数据类型及其在内存管理方面的角色

正如社区中的一些人所知道的,我教授Python课程,最受欢迎的是综合的入门+中级课程,以及介绍应用程序开发各个领域的“高级”课程。

经常有人问我类似这样的问题:“我应该上你的入门课还是进阶课?”我已经有1-2年的Python编程经验了,我认为入门部分对我来说太简单了,所以我想直接跳到高级部分…你推荐哪门课程?”

为了回答他们的问题,我考察了他们在这方面的能力有多强——并不是说这真的是衡量他们是否准备好了任何高级课程的最佳方法,而是看看他们对Python对象和内存模型的基本知识有多好,这是导致许多Python错误的原因,这些错误不仅是初学者写的,而且是那些已经超越了这一点的人写的。

要做到这一点,我建议他们看看这个简单的测试问题:

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.)

接下来的询问要求类似的答案就更难了,例如:

示例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, i.e. 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.我同意其他的回答,即更深入地进行内省以及研究其他项目的源代码,并在这两个建议中添加一个强烈的“+1”!

pp。顺便说一句,问得好。我希望我一开始就足够聪明,问过这样的问题,但那是很久以前的事了,现在我正试图用我多年的全职Python编程来帮助别人!!

你看过《用Python编程生物信息学》这本书吗?看来你是焦点小组的一员。

教那些刚开始学习Python的人总是让你的想法清晰的好方法,有时,我通常会从学生那里得到很多简洁的问题,让我重新思考关于Python的概念。

我认为掌握Python的过程是这样的:

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.