百倍加速 Python API

原文: PyCoder's Weekly - Issue #513

pycoder

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

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内存时...

)

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

)

Tutorial on configuring Django to run on Docker using Postgres, Nginx, and Gunicorn. All the ins-and-outs of Django in production.

(是也乎:

Docker 越来越象那个可以三步装入宇宙的冰箱了...

)

New standard for grouping exceptions together

(是也乎:

每年都发愿要解决的事儿...

)


探讨/吐糟

Discussions

(是也乎:

进入真实项目, 并快速完成, 再进入另外一个完全不同的项目

)

(是也乎:

admin 永远的 admin; 不过, 关联推荐给出很多神仙推荐:

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

The functools.wraps decorator keeps your function’s identity intact after it’s been wrapped by a decorator. Ever wondered how it works?

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

)

Learn about how venvs, flake8, black, isort, pytest, commitizen, semantic-release, pre-commit hooks, and Github Actions work together!

(是也乎:

嗯哼? 每年都值得更新一批, 这种悔不当初的工具集, 不过, 如果从20年前开始用 Python 的话, 又应该是什么呢?

)

What’s the output of "🇺🇸"[::-1]? A deep dive into the world of Unicode and how Python reverses strings.

(是也乎:

eomji 党派

)

Python classes can have arbitrary attributes. How are they stored and how do they impact performance?

(是也乎:

是的, Python 中包含太多独有的 ,只是依赖正确的消化姿势...

)

Tour Python’s itertools module and learn about cycle(), groupby(), chain(), and more.

(是也乎:

叕一个 itertools 科普文, 其实, 使用这些内置函式可以提高生产效能, 问题是, 并不一定提高代码撰写效率...

)

“Futures are a convenient abstraction in Python for running tasks in the background.”

(是也乎:

并发/迸发能力, 简直成为现代语言的基本操作素质了

)

Wye refactoring your code is important and hints on what to look for.

Using the email-validator library to validate an email address

(是也乎:

专项治理模块, 只是, 看是否支持 gmail 的 .+ 模式了

)


好物/妙品/...

Interesting Projects, Tools and Libraries, Projects & Code

(是也乎:

DevToys

就是将各种流行免费小工具集成为一个软件来发售, 很可以了...

)

(是也乎:

这类直接改动源代码的工具, 其实对于工程管理可能有帮助, 但是, 对于程序猿自身可能是反作用.

)

(是也乎:

Lurnby

叕一个 PKM 方案, 问题其实并没得到真正解决, 这些工具都是给私人一个构建私人资料网络的能力, 但是, 并没给予正确知识仓库维护的姿势...

)

(是也乎:

$ echo -e "example\nwikipedia" | pz 's += ".com"'
example.com
wikipedia.com

嗯哼? 这可是一直想拥有的管道能力哪...

)


📆🐍 活动/大会

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

(是也乎:

活动名不短

)

(是也乎:

虽然欧洲已经准备停止 COVID-19 的感染统计, 但是...

)


DAMA

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


PS:

PPS:

不觉中蟒周刊快译已经到了第10个年头

去年开始有小伙伴加入承担 pythonisa 周刊的翻译, 从来没提醒过, 可就这么默默坚持下来了...

问为什么:

[皱眉]每周新闻资讯 怎么能错过 
看看有什么新东西 
当有新的发现时:
    what f**k 还能这样玩? 还有这东西?
    每周开彩蛋[吃瓜]

无法同意更多... 很多社区贡献看起来辛苦, 其实受益最多的, 就是主动承担者也.


好文笔,感叹号年度配额: 1/3

投稿/反馈邮箱:

askdama@googlegroups.com

(邮件列表地址, 当成正常邮件发送邮件就好, 不用注册, 不用翻越...)


ZoomQuiet/大妈

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

私自嗯哼: ZoomQuiet (订阅号: ZoomQuiet42)
公开课程: 蟒营 (订阅号: Mainium)
历史吐糟: Chaos42 (订阅号 PythoniCamp)

as 创始组织者:
    PyChina (订阅号: PyChinaOrg)
    本地社区: 
        GDG珠海 (订阅号: GDG-ZhuHai)
        TFUG珠海 (订阅号: ZH_TFUG)


Comments


大妈的多重宇宙 - YouTube

全新自媒体系列...科学幻想,读书,说故事...

任何问题

随时邮件提问可也:
askdama@googlegroups.com

-->