百倍加速 Python API 原文: PyCoder’s Weekly - Issue #513 pycoder

  • 220222 Zoom.Quiet(大妈) 用时 13 分钟 完成快译
  • 220222 Zoom.Quiet(大妈) 用时 37 分钟 完成格式转抄.

  • 如何优化 Python API 服务器代码 100x
    • VADIM MARKOVTSEV
    • • Shared by Vadim Markovtsev Tricks we used to speed up calls to our analytical API written in Python: asyncio, SQLAlchemy, asyncpg, Cython plugins, improved data structures, and replaced some Pandas with NumPy. (是也乎: 在需要时… Optimized 反正都是些祖传手艺, 在电脑只有1K内存时… )
  • 在 Python 类中提供多个构造函数
    • REAL PYTHON Learn how to provide multiple constructors in your Python classes, including: checking argument types, using default argument values, writing class methods, and implementing single-dispatch methods. (是也乎: Multiple 模式匹配哪, 这是函式语言基本能力, 在 Python 中也可以模拟出来了… 基于 singledispatchmethod
from datetime import date
from functools import singledispatchmethod
class BirthInfo:
    @singledispatchmethod
    def __init__(self, birth_date):
        raise ValueError(f"unsupported date format: {birth_date}")
    @__init__.register(date)
    def _from_date(self, birth_date):
        self.date = birth_date
    @__init__.register(str)
    def _from_isoformat(self, birth_date):
        self.date = date.fromisoformat(birth_date)
    @__init__.register(int)
    @__init__.register(float)
    def _from_timestamp(self, birth_date):
        self.date = date.fromtimestamp(birth_date)
    def age(self):
        return date.today().year - self.date.year

)


探讨/吐糟

Discussions

How to run your website for less than $6/year. Domain - Namecheap FREE Static Site hosting - Netlify - Vercel - Github Pages - Render - Firebase Hosting - Surge - Cloudflare pages Free DB - Supabase - Mongo Atlas FREE Backend - Netlify functions - Vercel - Google functions )


文章/教程/嗯哼

Articles, Tutorials and Talks

  • Python’s functools.wraps 装饰器的内部结构
    • REDOWAN DELOWAR The functools.wraps decorator keeps your function’s identity intact after it’s been wrapped by a decorator. Ever wondered how it works?
  • 使用天气 API 绘制分形
    • REAL PYTHON
    • PODCAST Have you been wanting to explore fractals and complex numbers in Python? Would you like to practice working with APIs in Python through a new project? This week on the show, Christopher Trudeau discusses a fresh batch of PyCoder’s Weekly articles and projects. (是也乎: PODCAST )
  • 希望开始使用 Python 时就知道的 10 个工具
    • KEVIN YLU Learn about how venvs, flake8, black, isort, pytest, commitizen, semantic-release, pre-commit hooks, and Github Actions work together! (是也乎: 嗯哼? 每年都值得更新一批, 这种悔不当初的工具集, 不过, 如果从20年前开始用 Python 的话, 又应该是什么呢? )
  • 为什么你不能反转 国旗表情符号 字符串?
    • DAVID AMOS
    • • Shared by David Amos What’s the output of “🇺🇸”[::-1]? A deep dive into the world of Unicode and how Python reverses strings. (是也乎: eomji 党派 )
  • 理解 Python 中的 Attributes, Dicts and Slots
    • BAS STEINS Python classes can have arbitrary attributes. How are they stored and how do they impact performance? (是也乎: 是的, Python 中包含太多独有的 ,只是依赖正确的消化姿势… )
  • 游览 Python’s itertools Library
    • MIKE DRISCOLL Tour Python’s itertools module and learn about cycle(), groupby(), chain(), and more. (是也乎: 叕一个 itertools 科普文, 其实, 使用这些内置函式可以提高生产效能, 问题是, 并不一定提高代码撰写效率… )
  • Futures 简易并行化
    • JAIME BUELTA “Futures are a convenient abstraction in Python for running tasks in the background.” (是也乎: 并发/迸发能力, 简直成为现代语言的基本操作素质了 )
  • Bite-Sized 重构
    • RODRIGO GIRÃO SERRÃO Wye refactoring your code is important and hints on what to look for.
  • 用 Email-Validator 验证电子邮件地址
    • DIMITRIJE STAMENIC Using the email-validator library to validate an email address (是也乎: 专项治理模块, 只是, 看是否支持 gmail 的 .+ 模式了 )

好物/妙品/

Interesting Projects, Tools and Libraries, Projects & Code


📆🐍 活动/大会

Events, MeetUp 真的是全球线下活动组织中心


DAMA

❤️ Happy Pythonic ;-(大妈私人无责任播报)


PS

PPS

不觉中蟒周刊快译已经到了第10个年头 去年开始有小伙伴加入承担 pythonisa 周刊的翻译, 从来没提醒过, 可就这么默默坚持下来了… 问为什么: [皱眉]每周新闻资讯 怎么能错过 看看有什么新东西 当有新的发现时: what f**k 还能这样玩? 还有这东西? 每周开彩蛋[吃瓜] 无法同意更多… 很多社区贡献看起来辛苦, 其实受益最多的, 就是主动承担者也.


好文笔,感叹号年度配额: 1/3 投稿/反馈邮箱: [email protected] (邮件列表地址, 当成正常邮件发送邮件就好, 不用注册, 不用翻越…)

ZoomQuiet/大妈 就是四处 是也乎,( ̄▽ ̄) 的那个大妈:

私自嗯哼: ZoomQuiet (订阅号: ZoomQuiet42)
公开课程: 蟒营 (订阅号: Mainium)
历史吐糟: Chaos42 (订阅号 PythoniCamp)
as 创始组织者:
    PyChina (订阅号: PyChinaOrg)
    本地社区: 
        GDG珠海 (订阅号: GDG-ZhuHai)
        TFUG珠海 (订阅号: ZH_TFUG)