Python Tricks - Foreword

Foreword:
It’s been almost ten years since I first got acquainted with Python as a
programming language. When I first learned Python many years ago,
it was with a little reluctance. I had been programming in a different
language before, and all of the sudden at work, I was assigned to a
different team where everyone used Python. That was the beginning
of my own Python journey.

至从我接触python已经过去了十年了。多年前,当我第一次学习python的时候,我心里还是有小情绪的。我之前都是使用其他的编程语言,但是在工作中,我突然间被派到了一个每个人都使用python的团队。这就是我python旅程开始的地方。

When I was first introduced to Python, I was told that it was going to
be easy, that I should be able to pick it up quickly. When I asked my
colleagues for resources for learning Python, all they gave me was a
link to Python’s official documentation. Reading the documentation
was confusing at first, and it really took me a while before I even felt
comfortable navigating through it. Often I found myself needing to
look for answers in StackOverflow.

当我第一次接触python,有人告诉我python很简单,所以我应该很快就掌握它。当我向我的同事寻求学习python的资源时,他们都给我指向python官方文档的链接。刚开始读完文档是有疑惑的,而且花了不少时间,我才能比较自如的通过文档进行查询。我还是经常性的需要去StackOverflow上寻求帮助。

Coming from a different programming language, I wasn’t looking for
just any resource for learning how to program or what classes and
objects are. I was looking for specific resources that would teach me
the features of Python, what sets it apart, and how writing in Python
is different than writing code in another language.

因为有其他编程语言的基础,我并不是去学习该如何编程或者什么是类,什么是对象这些。我只是在寻找能展现python不同之处的语言特性的专项资源,合用python编程与其他语言编程不同的地方。

It really has taken me many years to fully appreciate this language. As
I read Dan’s book, I kept thinking that I wished I had access to a book
like this when I started learning Python many years ago.

这确实花了我许多年去彻底的欣赏这门语言。当我读到dan的书的时候,我多么希望是我在多年前彷徨的时候找到了这本书。

For example, one of the many unique Python features that surprised
me at first were list comprehensions. As Dan mentions in the book,a tell of someone who just came to Python from a different language
is the way they use for-loops. I recall one of the earliest code review
comments I got when I started programming in Python was, “Why
not use list comprehension here?” Dan explains this concept clearly
in section 6, starting by showing how to loop the Pythonic way and
building it all the way up to iterators and generators.

举个栗子,在诸多的python语言特性中,最让我感到惊异的是列表推导式。正如dan在书中所提到的,一些人正是因为python的for循环的书写方式而转到了python。我想起来我很早时候的一次代码审查中我收到的一个评价,“为什么不使用列表推导式呢?”dan在第六章通过如何很python的去循环并且如何创建迭代器和生成器很清晰地解释了这个概念。

In chapter 2.5, Dan discusses the different ways to do string formatting
in Python. String formatting is one of those things that defy the
Zen of Python, that there should only be one obvious way to do things.
Dan shows us the different ways, including my favorite new addition
to the language, the f-strings, and he also explains the pros and cons
of each method.

在2.5章节中,dan讨论了不同的方法去实现字符串的格式化。字符串的格式化问题是违反了python之禅的问题之一,而后者显然应该是我们需要去践行的。dan向我们展现了不同的方式,包括我最喜欢的新特性,f方式,而且他还解释了各种方法的优点和缺点。

The Pythonic Productivity Techniques section is another great resource.
It covers aspects beyond the Python programming language,
and also includes tips on how to debug your programs, how to manage
the dependencies, and gives you a peek inside Python bytecode.

python化的生产力技术这一章也是极好的。它重复介绍了python这门编程语言并且涵盖了如何去调试自己的代码,怎么去管理依赖包的技巧,介绍了一下python的字节码。

It truly is an honor and my pleasure to introduce this book, Python
Tricks, by my friend, Dan Bader.

这是我的荣幸来为我的朋友dan做序。

By contributing to Python as a CPython core developer, I get connected
to many members of the community. In my journey, I found
mentors, allies, and made many new friends. They remind me that
Python is not just about the code, Python is a community.

Mastering Python programming isn’t just about grasping the theoretical
aspects of the language. It’s just as much about understanding and
adopting the conventions and best practices used by its community.

Dan’s book will help you on this journey. I’m convinced that you’ll be
more confident when writing Python programs after reading it.

— Mariatta Wijaya, Python Core Developer

以上感谢的话就不翻译了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,752评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,100评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,244评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,099评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,210评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,307评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,346评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,133评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,546评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,849评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,019评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,702评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,331评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,030评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,260评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,871评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,898评论 2 351

推荐阅读更多精彩内容