411-420¶
Issue #411 Jupyter Notebooks in 2020, psycopg3, PyCon COVID-19 Update, and More March 10, 2020¶
Cite
We Have to Talk About This Python, Gunicorn, Gevent Thing
“Here’s what happens when you build around Python, Gunicorn, Gevent, and web requests instead of something more sensible.” Although pessimistic, this was an interesting read.
RACHELBYTHEBAY.COM OPINION
说啥呢
Cite
Defining Main Functions in Python
Learn how Python main functions are used and some best practices to organize your code so it can be executed as a script and imported from another module.
REAL PYTHON VIDEO
看不了
Issue #412 Questionable Python Code Metrics, Django Governance, Conference Updates, and More March 17, 2020¶
Cite
The Most Critical Python Code Metric
“Code metrics are a popular way to analyse the complexity of our software. For some reason, we are attracted to single-figure summaries of quality, whether it’s lines of code, cyclomatic complexity, or the Pylint score. Personally, I think using these are about as valuable as judging another person based on one of their visible or measurable characteristics.”
STEVE DOWER
结论就是Python要多写测试,测试可以保证你的代码的靠谱
Cite
Do Not Log
What makes a good log? When should you log something, and when is logging overkill? In this opinion piece, Nikita Sobolev argues that logging isn’t always best-practice in an application and discuss some alternatives that might make better sense from a business perspective.
NIKITA SOBOLEV
因为看到了mypy,就被带跑了,顺势学了一波变量声明和dataclass 2020/3/22 20:59 意思就是真想写log你就用专业的sentry ,不需要你就别写,写个log没啥用,感觉有点极端
Cite
How to Do a Binary Search in Python
Binary search is a classic algorithm in computer science. In this step-by-step tutorial, you’ll learn how to implement this algorithm in Python. You’ll learn how to leverage existing libraries as well as craft your own binary search Python implementation.
REAL PYTHON
使用bisect 模块进行快速的查找操作
Cite
Why Does all() Return True if the Iterable Is Empty? Does it make sense for all() to return True for an empty list? Is “all unicorns are blue” a true statement? Does shaving your dog contradict the statement “all mammals have fur?” You’ll have to read to find out! CARL JOHNSONS
这事说起来可就话长了
从字面上看,这是一个有2500年历史的哲学争论。古人认为“所有独角兽都是蓝色的”应该是错误的,因为没有独角兽,但现代逻辑认为这是真的,因为没有独角兽不是蓝色的。 Python仅是现代谓词逻辑的一部分,但是您的直觉也很普遍,并且直到最近几百年来一直是正统的。
treq 做异步请求
Cite
HPI: Human Programming Interface
GITHUB.COM/KARLICOSS
自己用的小工具
Issue #413 PyCon 2020 Is Cancelled, New Pip Resolver, Scope/LEGB Explained, and More March 24, 2020¶
Cite
New pip Resolver to Roll Out This Year
“The developers of pip are in the process of developing a new resolver for pip (as we announced on the PSF blog last year). We aim to roll it out later this year. As part of that work, there will be some major changes to how pip determines what to install, based on package requirements.”
PSF BLOG
预计2020下半年发布,如果你要求安装俩不兼容的包,新的pip会直接拒绝,而不是像现在可以安装但是无法工作,感觉poetry要失业了
Cite
CPython 3.9.0a5 Now Available for Testing
PYTHON.ORG
1
Cite
PySimpleGUI-COVID19: Tools to Help Analyze the Spread of the COVID-19 Virus
GITHUB.COM/PYSIMPLEGUI • Shared by PythonistaCafe
看了眼布局
Issue #414 Django vs Flask, Feature Importance, Making Python Games, and More March 31, 2020¶
Cite
Are F-Strings Good Practice?
REDDIT
f-string这么新,3.6才有的
Cite
Django vs. Flask in 2019: Which Framework to Choose [2019]
”[…] Django and Flask are by far the two most popular Python web frameworks… In the end, both frameworks are used to develop web applications. The key difference lies in how they achieve this goal. Think of Django as a car and Flask as a bike. Both can get you from point A to point B, but their approaches are quite different.”
MICHAEL HERMAN
比较详细的对比,结论跟以前的一样
Cite
How to Use any() in Python
If you’ve ever wondered how to simplify complex conditionals by determining if at least one in a series of conditions is true, then look no further. This tutorial will teach you all about how to use any() in Python to do just that.
REAL PYTHON
any和or的不同用法
Issue #415 Python + Arduino, Final Python 2.x Release, Effective Python 2nd Ed., and More April 7, 2020¶
Cite
confight: One Simple Way of Parsing Configs
GITHUB.COM/AVATURE
管理配置,没怎么看,应该用不到
Cite
cliche: Build a Simple Command-Line Interface From Your Functions
GITHUB.COM/KOOTENPV
我觉得还是很优雅的
Issue #416 Pythonic Video Conferencing, OOP Inheritance vs Composition, Faster Pandas, and More April 14, 2020¶
Cite
Stop Naming Your Python Modules utils
“Do not use utils as a name for your Python module neither put it into a class name. Try to be more specific about the role of code – e.g. create a place for validators, services or factories. If the role criterion doesn’t help and you really dealing with utils, try grouping code by its theme.”
SEBASTIAN BUCZYŃSKI OPINION
utils太笼统了,妈的我的项目里就好多utils
Cite
How Can I Simplify Repetitive if/elif Statements?
Comparing a single value against a number of conditions can result in long if/elif blocks. Is there a short and clean way to handle these comparisons?
STACK OVERFLOW
这个问题下面的回答真是花里胡哨集大成者
Cite
An Overview of Profiling Tools for Python
MIKE DRISCOLL
line_profiler跟memory_profiler有异曲同工之妙,可以用来逐行的分析代码运行时间
Issue #417 New pip Resolver, Pathlib Is Great, Effective pytest, Python Interview Tips, and More April 21, 2020¶
Cite
pip 20.1b1 Released With the New Dependency Resolver
The beta release of pip version 20.1 has dropped and included the next-generation dependency resolver! The resolver is currently turned off by default because it’s unstable and not ready for everyday use. The pip mainainters do encourage users to try it out, however, and feedback on the new resolver can be submitted by filling out a survey.
GITHUB.COM/PYPA
三个月一次更新
Cite
No Really, Python’s Pathlib Is Great
Python 3’s pathlib module has taken some time to gain traction since it was introduced in Python 3.4. After all, the os.path module had been the de facto tool for working with paths in Python. Why change code that works? Learn why pathlib is a better choice for working with file paths in Python in this thorough tutorial.
REDOWAN DELOWAR • Shared by Redowan Delowar
已结全部从os.path转到pathlib了
Cite
x += 1 vs x = x + 1
Are there certain situations where one is more useful than the other?
REDDIT
x+=1会在原地修改x,x=x+1会新创建一个变量然后赋值给x
Cite
HPy: A Future-Proof Way of Extending Python?
“HPy is a joint project which is being developed by PyPy, CPython and Cython developers. It aims to design a better C API for writing Python extensions which is more friendly to alternative implementations and which would allow CPython itself more freedom to experiment (e.g. by using a real GC instead of refcounting).”
ANTONIO CUNI
https://github.com/pyhandle/hpy 看起来很有前途,star一下没准哪天就火了
Issue #418 The End of the Python 2 Era, New Features in Python 3.9, Common Python App Layouts, and More April 28, 2020¶
Cite
The Final Python 2 Release Marks the End of an Era
The final version of Python 2 has been released. As the Python community looks forward to the new era, Ryan Donovan from the Stack Overflow Blog takes some time to reflect on the transition and points out that, while support for Python 2 from official channels may be gone, the language isn’t dead. In fact, there’s reason to believe it will live on for decades to come.
RYAN DONOVAN
都不支持了,还发新版本
Cite
New Features in Python 3.9 You Should Know About
Python 3.9 is scheduled for release on May 10, 2020, and it’s packed full of new goodies. Explore these new features in this overview by Martin Heinz, including new dict operators, updates to the math module, new string methods, a functools.ToplogicalSorter class, and more!
MARTIN HEINZ • Shared by Martin Heinz
math里面有gcd了,不用自己写了,nice啊
Cite
The Python pickle Module: How to Persist Objects in Python
In this tutorial, you’ll learn how you can use the Python pickle module to convert your objects into a stream of bytes that can be saved to a disk or sent over a network. You’ll also learn the security implications of using this process on objects from an untrusted source.
REAL PYTHON
- pickle比json好用,但是也不是啥都能序列化
- pickle序列化不了的,可以试试dill,可以序列化的更多
- 反序列化可能会有风险,因此反序列化要确认是信任的
Cite
How to Convert .py to .exe You’ve just created a Python project, but how can you easily distribute it as a one-click file? Fortunately, there are Python utilities that help convert files to .exe. Check out ActiveState’s tutorial that steps you through how to create an executable for your Python script → ACTIVESTATESPONSOR 除了Pyinstaller,又介绍了一个打包工具cx_freeze,没仔细看,看也是难用
Cite
Best Practices for Working With Configuration in Python Applications
Users love being able to configure an application. But dealing with user configuration means parsing untrusted input, validating that input, and figuring out how to access it safely in all the layers of your applications. Python has a rich configuration ecosystem. Lots of articles focus on how to use various configuration formats in your Python programs but skip out on the finer details of how and when configuration should be validated. This tutorial fills in some of those gaps.
TOBIAS PFEIFFER
海星
Issue #419 Python 3.9 Release Schedule, Documenting Tests, RegExes, Pythonic Lightsabers, and Mor May 5, 2020¶
Cite
Python 3.9 Release Schedule
In last week’s issue we had the dates mixed up, here are the correct ones: 3.9.0 final is expected to be released on October 5, 2020. On May 18, 2020 3.9.0 beta 1 is going to be released, marking the start of the feature freeze phase.
PYTHON.ORG
如题
Cite
Python 3.9.0a6 Is Now Available for Testing
PYTHON.ORG
Alpha版本
Cite
Why Doesn’t [1] += {'a': 2} Raise a TypeError?
Wait… you can do that?
STACK OVERFLOW
Cite
Why Does True == False Is False Evaluate to False in Python? (2013)
A real brainteaser if you don’t know about chained comparisons.
HACKER NEWS
太长不看
Cite
Using Python datetime to Work With Dates and Times
Have you ever wondered about working with dates and times in Python? In this tutorial, you’ll learn all about the built-in Python datetime library. You’ll also learn about how to manage time zones and daylight saving time, and how to do accurate arithmetic on dates and times.
REAL PYTHON
基本介绍
Issue #420 Python Performance, Moving Django Models, the 2020 Python Language Summit, and More May 12, 2020¶
Cite
Under Discussion: The Performance of Python
Victor Stinner and Julien Danjou sat down (remotely, that is) with Anne-Laure Civeyrac to talk about Python’s performance. They discuss everything from profiling, why Python is slow, and projects aimed at improving Python’s performance. Check it out!
ANNE-LAURE CIVEYRAC
采访 没啥有用的话
Cite
Which Characters Are Considered Whitespace by split()?
If you’re porting some Python 2 code to Python 3, you might want to check this out.
STACK OVERFLOW
Cite
The Python World Has Shown Increased Preference for Double Quotes
Is this the new tabs vs. spaces? Which do you prefer?
RAYMOND HETTINGER ON TWITTER
….因为可以少按一下shift么…
Cite
Python eval(): Evaluate Expressions Dynamically
Learn how Python’s eval() built-in works and how to use it effectively in your programs. Additionally, you’ll learn how to minimize the security risks associated with the use of eval().
REAL PYTHON
eval其实还有俩参数,用来指定全局变量和局部变量
Cite
Monitoring Python Flask Microservices With Prometheus
Learn how to set-up Prometheus on a Flask application to serve up metrics like requests-per-second, average response time, memory usage, and CPU usage.
VIKTOR ADAM
看起来挺好的
Cite
tqdm: A Fast, Extensible Progress Bar for Python and CLI
GITHUB.COM/TQDM
之前用过终端看挺好的,就是如果写日志的话进度条每动一下就会写一下,实在是太多了