Issue 396

Guido: 代码的可读性如此重要… 原文: PyCoder’s Weekly - Issue #396 191127 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191127 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. PyCon 2020 注册已上线 PYCON.ORG PyCon is the largest annual gathering for the community that uses and develops the open-source Python programming language. April 15–23 in Pittsburgh. Pro-tip: Get your early bird tickets today. (是也乎: PyCon2020 早鸟票已经有了,,, ) Python KeyError 异常以及如何处理它们 REAL PYTHON video KeyError exceptions are often caused by a bad key lookup in a dictionary, but there are a few other situations when a KeyError can be raised as well. Knowing how to handle these exceptions is essential to writing good Python code. (是也乎: 等等, 这个是常见, 但是, 不难追踪哪… ) 实用 Unicode (2012) NED BATCHELDER Timeless tutorial that teaches the basics of Unicode, and how both Python 2 and Python 3 work, as well as some key tips on solving Unicode problems. Guido van Rossum 论 Python 如何令思维的代码表述更轻松 DROPBOX.COM A conversation with the creator of the world’s most popular programming language on removing brain friction for better work. (是也乎: 全文如下: The Mind at Work: Guido van Rossum on how Python makes thinking in code easier By Anthony Wing Kosner Published on November 25, 2019 A conversation with the creator of the world’s most popular programming language on removing brain friction for better work. Nothing defines the 21st century more than the ubiquitous effects of computer programming. Almost everything we do, particularly at work, is mediated by screens displaying the results of the enormous amount of computation that we now take for granted. If you’re one of the 99.7% of the human race that are not programmers, how all of this happens is a bit of a mystery. As science fiction writer Arthur C. Clarke quotably wrote, “Any sufficiently advanced technology is indistinguishable from magic.” Of course, it isn’t magic. It is, however, both complicated and complex, with codebases of tech companies measured in millions of lines of code. When you’re reasoning about a real system you might want to build in code, you’re thinking about the complex relationships between different functions over time. Your code can be more or less complicated in how it is written and structured, but the problem you’re trying to solve has an inherent complexity that can’t be reduced to something simpler. Becoming a programmer is not just about ideas, and you won’t last long at it if you can’t deal with the laser-focused details of describing your ideas in code. “I’m a little skeptical of the claim that the systems thinking is primary there, because it’s much easier to come up with an idea for a system than it is to take an idea and turn it into working code,” says Guido van Rossum, the creator and retired BDFL (Benevolent Dictator for Life) of the Python programming language. JavaScript still owns the web, and Java runs 2.5 billion Android phones, but for general purpose programming and education, Python has become the default standard. If anyone has made turning an idea into working code easier, for more people, it’s Van Rossum over his 30-year history with Python. And he’s done it with a self-effacing grace and an understated humor—the language is named after the surreal comedy of Monty Python, not the actual Burmese python. In its quiet way, the Python programming language has managed to make some of the complications of programming computers less difficult for our brains to manage. To understand how Van Rossum accomplished this amazing feat, we have to go back into the history of computing to the era of mainframes and machine language. “The mainframe is a machine that costs many millions of dollars, and the combined pay of all those programmers is peanuts compared to the cost of the mainframe,” he says, explaining that cost logically prioritized machine time over human time. “But as I experienced desktop workstations and PCs, I realized that a change of mindset about cost of the programmer’s time versus cost of the computer’s time was overdue.” Van Rossum doesn’t think he was the first person to observe this shift, but he really capitalized on it in the design of Python. This simple idea of giving humans priority over machines is at the core of the philosophy behind Python. Certainly the fact that it’s an interpreted language as opposed to a compiled language means that the programmer gets immediate feedback about the code they’re writing without needing to take the time to recompile it after making each change. This is very common now, but thirty years ago it was quite controversial because the conventional wisdom was that faster (for the computer) was better. Updating this belief has had a large positive impact on the productivity of programmers. “In Python, every symbol you type is essential.” —Guido van Rossum “There are a whole bunch of common programming tasks that are easy in Python,” says Van Rossum. “For someone who is not yet a programmer, who wants to become a programmer, for those people Python is particularly easy to get.” Indeed, many computer science schools are switching over from Java to Python, because it’s much easier to grasp for beginners. The reasons behind this are complex, with many factors each reducing little bits of friction. What’s simple is the philosophy behind all of the improvements: Everything should have a necessary purpose. The lack of extraneous code makes it easier to focus on what you need to pay attention to. “In Python, every symbol you type is essential,” Van Rossum says. This concision makes it easy to accomplish something meaningful in Python, which is one of the reasons for its wide adoption. “The typical way that we introduce Python to beginning programmers is also important. We can show them very small snippets of code that require very little understanding of terminology and concepts from programming before they make sense,” Van Rossum explains, “whereas the smallest Java program, for example, contains a whole bunch of what are, to the uninitiated eye, noise characters.” This quietness and simplicity of design makes it easier to see what’s going on. “Python for me is incredibly visual,” says Van Rossum. “When I read Python, I definitely see it as a two-dimensional structure, rather than one-dimensional, like language. That is probably because Python uses indentation for grouping, but probably also because my mind just likes thinking visually.” He’s not the only one, of course, who thinks visually. We all do to some extent. But he’s particularly sensitive to the effects of the visual on cognition. “Some poorly formatted text can drive me crazy. They interrupt my visual parsing of the flow and the structure, and in that sense, I do think in Python,” Van Rossum admits. “I can grasp code much better when it’s formatted properly.” It takes more information to resolve the uncertainty about what code indentations mean if they’re arbitrary than if those indentations have a clear purpose, as they do in Python. So if the experience is easier, it’s because fewer bits of information have to be processed for you to know what’s going on. Python’s readability is not just typographic, but conceptual. Van Rossum thinks Python may be closer to our visual understanding of the structures that we are representing in code than other languages because, “Python makes that structure mandatory.” “While I was researching my book, CODERS,” says author Clive Thompson, “I talked to a lot of developers who absolutely love Python. Nearly all said something like ‘Python is beautiful.’ They loved its readability—they found that it was far easier to glance at Python code and see its intent. Shorn of curly brackets, indented in elegant visual shelves, anything written in Python really looks like modern poetry.” They also find that Python is fun to write, which is more important than it may seem. As Thompson writes, “When you meet a coder, you’re meeting someone whose core daily experience is of unending failure and grinding frustration.” “You primarily write your code to communicate with other coders, and, to a lesser extent, to impose your will on the computer.” —Guido van Rossum Building the priority of the programmer’s time into the language has had a curious effect on the community that’s grown around it. There’s a social philosophy that flows out of Python in terms of the programmer’s responsibility to write programs for other people. There’s an implicit suggestion, very much supported by Van Rossum in the ways he talks and writes about Python, to take a little more time in order to make your code more interpretable to someone else in the future. Expressing your respect for others and their time through the quality of your work is an ethos that Van Rossum has stealthily propagated in the world. “You primarily write your code to communicate with other coders, and, to a lesser extent, to impose your will on the computer,” he says. The universality of the culture that’s spread around Python has achieved some measure of what Van Rossum intended two decades ago with a short-lived project called CP4E (Computer Programming for Everybody). “I’m usually not a very visionary thinker. People always ask me, what’s next for Python, and I never know. But I put on my most visionary hat, and assumed that it would make sense for everyone to learn programming.” Personal computers had been around for 20 years, but mostly they were glorified typewriters and calculators. Van Rossum asked, “isn’t it crazy that all those people have computers, and very few of them learn to program?” In the time since, he has focused on making programming easier to learn and easier to do through the advancements in Python, now at version 3.7. He still thinks that programming teaches generally valuable skills, like problem solving, following directions carefully, and understanding what directions mean. But he’s also found that, “there are certain introductions to programming that are fun for kids to do, but they’re not fun for all kids, and I don’t think I would want to make it a mandatory part of the curriculum.” At the same time, the need for people to program their computers has also diminished because of the growth of software, particularly on the web, that allows you to intuitively do what used to require programing to accomplish. “I’m not so sure that it needs to happen anymore,” Van Rossum says of CP4E. “I think computers have made it to that point, where they’re just a useful thing that not everybody needs to know what goes on inside.” “Python is now also the language of amateurs, and I mean that in the best possible way.” —Guido van Rossum But that are a growing number of people who are using Python in many fields. “The currently prevailing theory about Python’s unexpected success,” says Van Rossum, “is that at some point, it established itself into data science and machine learning, and scientific data processing in general, and once you have critical mass, it’s easier for everyone to use the same system as their colleagues and their competitors, than to try something different.” And even though it started as purely a tool for professional programmers, Van Rossum says, “Python is now also the language of amateurs, and I mean that in the best possible way.” A successful open source software project, like Python, has to be easy to learn for beginners, but also have practical application to real world problems that more advanced users will want to solve. Just as for beginners you want to keep things simple so all of their brain energy is spent on learning the complications of the programming environment, for advanced users you want to help them manage the complexity of these competing abstractions. Part of the motivation for making the implementation of Python as simple as possible is to be able to change your mind, to learn, to iterate. “If you write a prototype in Python and you get it to work, often, that’s not a very big effort,” says Van Rossum, “and then you can afford to throw away your prototype and write the same thing again based on what you’ve learned. You can still write it in Python, but the second version will be much better than the first.” Part of the enduring appeal of Python is the optimism and humility of starting over. “If you’ve invested much more time into writing and debugging code, you’re much less eager to throw it all away and start over.” Co-founder and CEO, Drew Houston wrote the first prototype of Dropbox in Python on a five-hour bus ride from Boston to New York. “The early prototypes of Dropbox were thrown away, largely, many times,” says Van Rossum. What can we learn from Python about how to design better tools for thinking? Tim Peters, one of Python’s major contributors, offers some clues in the aphoristic The Zen of Python, in which he channels Van Rossum’s guiding principles. Particularly relevant to our present discussion are this pair: “Simple is better than complex. Complex is better than complicated.” This could almost be a recipe for how the brain prioritizes its functions to use energy efficiently. Equally important for Van Rossum is the social aspect of thinking and building tools. What has he taken away from his thirty year journey with Python? “I have learned that you can’t do it alone, which is not an easy lesson for me. I’ve learned that you don’t always get the outcome that you went for, but maybe the outcome you get is just as good, or better.” 简单说: Python 之禅 真的包含了老爹所有关键思考成果. ) ...

2019-11-27 · 8 min · 3627 words · ZoomQuiet

pythonista-weekly : Pyw 423

欢迎阅读"pythonista周刊"第423期. Let us start 原文: https://mailchi.mp/pythonweekly/python-weekly-issue-423 翻译:Dustyposa 来自赞助商 python开发者都需要的Vettery Vettery是一个招聘网站,它改变了人们应聘或者雇佣的方式. 准备好换工作地方了吗?免费制作简历,你的薪资你说了算,现在就和顶级雇主的HR联系吧! ...

2019-11-19 · 7 min · 3457 words · ZoomQuiet

Issue 394

俺的 Python 开发环境 2020 版 原文: PyCoder’s Weekly - Issue #394 191113 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191113 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. PSF 寻求开发商以提高 pip 品质 PYFOUND.BLOGSPOT.COM • Shared by Brian Rutledge The Python Software Foundation Packaging Working Group is receiving funding to work on the design, implementation, and rollout of pip’s next-generation dependency resolver. Funding has been allocated to secure a senior developer and an intermediate developer, starting in December 2019 or January 2020. RFP open now through November 22. 俺的Python开发环境,2020版 JACOB KAPLAN-MOSS The co-creator of Django explains his Python environment: “My setup pieces together pyenv, poetry, and pipx. It’s probably a tad more complex than is ideal for most Python users, but for the things I need, it’s perfect.” Related discussion on Hacker News. (是也乎: 来了, 又来了, 每年更新最具有引战体质话题… pipenv 被弃用非常明智… ) 何时在Python中使用列表推导 REAL PYTHON Python list comprehensions make it easy to create lists while performing sophisticated filtering, mapping, and conditional logic on their members. In this tutorial, you’ll learn when to use a list comprehension in Python and how to create them effectively. (是也乎: 最讨巧也最容易滥用的技巧… 简单说: 在应该使用时 ) Python中的"解析" ASTHASR.GITHUB.IO “Don’t be afraid to create new, more specific data types for your specific use cases. It’s okay to represent different data, used for different purposes, with different data structures, and makes later generalization easier!” (是也乎: 毕竟 Python 内置的, 而对其它对象的分析, Python 生态中工具也是最多的… 所以, 嫑怕, 放心定制自己舒服的… ) 使用 Keras 和深度学习发现自然灾害 ADRIAN ROSEBROCK In this tutorial, you will learn how to automatically detect natural disasters (earthquakes, floods, wildfires, cyclones/hurricanes) with up to 95% accuracy using Keras, Computer Vision, and Deep Learning. Python 成为 GitHub 第二受欢迎的语言 DEVELOPER-TECH.COM GitHub has published its latest State of the Octoverse report which provides fascinating insights into the development industry. (是也乎: 第一当然是 JAVA 了, 报告中还有其它有趣的结论: 谁是增长最快的语言? 哪个编辑器最受欢迎… 当然, 无论调查如何, 自己舒服的才是最好的. ) 简单便携式 Python 解释器的复杂路径 GLAUBER COSTA “We needed a Python interpreter that can be shipped everywhere. You won’t believe what happened next!” (是也乎: 简单说, 用专用工具来完成…别自己乱来… ) 那些最为低估的 Python 软件包 EYAL TRABELSI (是也乎: 除了 this 模块之外, 在各种领域都散落有官方一直没注意到的神奇模块, 当然, 多数都是和大数据相关的, pandas 插件, 数据清理/探索, 以及性能检测什么的… 值得逐一尝试体验… ) 停止使用 utcnow 以及 utcfromtimestamp PAUL GANSSLE (是也乎: 简单说 datetime 才是最好的选择. ) 讨论 Discussions NIL ...

2019-11-13 · 4 min · 1911 words · ZoomQuiet

Issue 395

激萌模块->用表情符编写Python程序 原文: PyCoder’s Weekly - Issue #395 191120 Zoom.Quiet(大妈) 用时 42 分钟 完成快译 191120 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄. Python 中咯线程 REAL PYTHON video Learn how to use threading in your Python programs. You’ll see how to create threads, how to coordinate and synchronize them, and how to handle common problems that arise in threading. (是也乎: 基础而又不简单的嗯哼… ) 加载较少数据来减少 Pandas 内存用量 ITAMAR TURNER-TRAURING How to reduce the memory your DataFrame uses at the time it is initially loaded: by dropping columns, lower-range numerical dtypes, and categoricals. Python 字典"加法"的回归 JAKE EDGE An interesting summary of discussions around PEP 584 (“Add + and += operators to the built-in dict class”). 为什么向 Python 3 迁移需要这么长时间? VICKI BOYKIS (是也乎: 因为, 多数项目没法儿迁移… ) Related discussion on Hacker News. Django 3.0 RC 1 可用矣 DJANGOPROJECT.COM PyCon 2020 Tutorial 提案截止日期临近 PYCON.BLOGSPOT.COM 讨论 Discussions ...

2019-11-13 · 4 min · 1851 words · ZoomQuiet