Python隨身聽-全球技術精選-20191230

Hey,你好,歡迎來到 Python 隨身聽週一的《全球技術精選》。

這一次 DE8UG 給你帶來的是:

  • 四款新的值得關注的代碼庫
  • 兩款需要長期持有的代碼庫

四款新的值得關注的代碼庫

Typical: Fast, simple, & correct data-validation using Python 3 typing.

直接通過裝飾器@typic.al,然後自動根據 Python3 的註解功能自動判斷輸入參數類型。

更多查看:https://github.com/seandstewart/typical/

示例:

>>> import typic
>>>
>>> @typic.al
>>> def multi(a: int, b: int):
...    return a * b
...
>>> multi('2', '3')
6

>>> class DuckRegistry:
...     """A Registry for all the ducks"""
...
...     @typic.al
...     def __init__(self, *duck: Duck):
...         self._reg = {x.name: x for x in duck}
...
...     @typic.al
...     def add(self, duck: Duck):
...         self._reg[duck.name] = duck
...
...     @typic.al
...     def find(self, name: str):
...         """Try to find a duck by its name. Otherwise, try with type."""
...         if name not in self._reg:
...             matches = [x for x in self._reg.values() if x.type == name]
...             if matches:
...                 return matches[-1] if len(matches) == 1 else matches
...         return self._reg[name]
...
>>> registry = DuckRegistry({'type': 'black', 'name': 'Daffy'})
>>> registry.find('Daffy')
Duck(type=<DuckType.BLK: 'black'>, name='Daffy')
>>> registry.add({'type': 'white', 'name': 'Donald'})
>>> registry.find('Donald')
Duck(type=<DuckType.WHT: 'white'>, name='Donald')

>>> registry.add({'type': 'goose', 'name': 'Maynard'})
Traceback (most recent call last):
 ...
ValueError: 'goose' is not a valid DuckType

pylightxl:A light weight Microsoft Excel File reader.

一個新的輕量級 excel 讀寫工具。因爲太新了,所以 write 的功能還在路上。。。

目前特點如下:

  • Zero non-standard library dependencies (standard libs used: zipfile, re, os, sys).
    No compatibility/version control issues.
  • Single source code that supports both Python37 and Python27. The light weight library is only 3 source files that can be easily copied directly into a project for those that have installation/download restrictions. In addition the library’s size and zero dependency makes pyinstaller compilation small and easy!
  • 100% test-driven development for highest reliability/maintainability with 100% coverage on all supported versions
  • API aimed to be user friendly, intuitive and to the point with no bells and whistles. Structure: database > worksheet > indexing
    example: db.ws(‘Sheet1’).index(row=1,col=2) or db.ws(‘Sheet1’).address(address='B1)

更多:
https://pylightxl.readthedocs.io/en/latest/

ffmpeg-python:Python bindings for FFmpeg - with complex filtering support

Python 讓使用 ffmpeg 處理視頻文件變得更簡單,比如把

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0]trim=start_frame=10:end_frame=20[v0];\
    [0]trim=start_frame=30:end_frame=40[v1];[v0][v1]concat=n=2[v2];[1]hflip[v3];\
    [v2][v3]overlay=eof_action=repeat[v4];[v4]drawbox=50:50:120:120:red:t=5[v5]"\
    -map [v5] output.mp4

變爲:

import ffmpeg

in_file = ffmpeg.input('input.mp4')
overlay_file = ffmpeg.input('overlay.png')
(
    ffmpeg
    .concat(
        in_file.trim(start_frame=10, end_frame=20),
        in_file.trim(start_frame=30, end_frame=40),
    )
    .overlay(overlay_file.hflip())
    .drawbox(50, 50, 120, 120, color='red', thickness=5)
    .output('out.mp4')
    .run()
)

python-small-examples

Python 有趣的小例子一網打盡。Python 基礎、Python 坑點、Python 字符串和正則、Python 繪圖、Python 日期和文件、Web 開發、數據科學、機器學習、深度學習、TensorFlow、Pytorch,一切都是簡單易懂的小例子。

https://github.com/jackzhenguo/python-small-examples

兩款需要長期持有的代碼庫

下面這兩個庫請一定收藏並經常查看。對工作,面試都非常重要。

interview_internal_reference

鮮活的面試題,2019 年最新總結,阿里,騰訊,百度,美團,頭條等技術面試題目,以及答案,專家出題人分析彙總。

https://github.com/0voice/interview_internal_reference

system-design-primer

項目目的:

  • 學習如何設計大型系統。
  • 爲系統設計的面試做準備。

學習如何設計可擴展的系統將會有助於你成爲一個更好的工程師。系統設計是一個很寬泛的話題。在互聯網上,關於系統設計原則的資源也是多如牛毛。

這個倉庫就是這些資源的組織收集,它可以幫助你學習如何構建可擴展的系統。

這是一個不斷更新的開源項目的初期的版本。特別是中文版很多地方沒翻譯好(DE8UG 注),建議還是看英文版,因爲圖很多的。

https://github.com/donnemartin/system-design-primer

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章