[閒聊] Python 3.5.0b2 release
Python 3.5.0b2 release
link: https://docs.python.org/3.5/whatsnew/3.5.html
What's New (compared to 3.4)
Syntax features:
- matrix multiplication operator: a @ b
- coroutines with async and await syntax (PEP492)
New lib modules:
- zipapp
New built-in features:
- bytes % args, bytearray % args
- hex() method has been added to bytes, bytearray
and memoryview
Significatly Imporved Library Modules:
- collections.OrderedDict is now implemented in C (4x~100x)
- tempfile
Implementation Improvements:
(略,看不懂)
Security Improvements:
None yet
--------------------------
PEP 492: Coroutines with async and await syntax
以前判斷是否為coroutine的方法為檢查function body中
是否有yield from or yield,但這種作法在refactoring
的時候, yield or yield from的消失或出現會造成不明顯
的錯誤。
過去asynchronous calls會因為yield的語法限制,不被
允許出現在with和for中。
- async with, async for
Example:
async def read_data(db):
async with db.transaction():
data = await db.fetch('SELECT ...')
---------------------------
在看async東西時剛好看到doc後面沒掛(dev)就放上來分享。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.40.10
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1433802076.A.992.html
Python 近期熱門文章
PTT數位生活區 即時熱門文章