在Python中拆开包装
Dict Unpacking in Python

原始链接: https://github.com/asottile/dict-unpacking-at-home

妈妈我们可以在python中打开包装吗?不认真。 I do not need another joke package of mine to be deemed "critical" to pypi 1 pip install dict-unpacking-at-home add # -*- coding: dict-unpacking-at-home -*- to the top of your file (second line if you have a shebang) enjoy! # - * - 编码:dict-unpacking-at-at-at-at-at-at-at-at-t = {'engreting':'hello','hello','thing':'world'} {engreting,thing} = dct print(问候,问候,问候,事物)#hello hello world#,即使嵌套! dct = {'a':[1,2,3]} {'a':[1, *rest]} = dct print(REST)#[2,3]当前版本中断stacktraces中的线号 - 正确的线 - 数字分支有修复。但是以多少代价。另请参阅请不要以每月近一百万次下载和30m+总数使用此信息。

该黑客新闻线程讨论了Python中的“编解码”,该线程使词典打开包装,这是许多用户想要的功能。原始帖子使用Python的文本编码机制展示了一个有趣的实现,以预处理源代码。 评论者辩论词典解开包装的有用性和潜在陷阱。有些人赞扬其符合人体工程学,并表示沮丧,因为它不是标准功能,在JavaScript中引用了类似的功能。其他人则强调了现有的Python工具,例如“巫术”和“ Itemgetter”,可提供相关功能。 一个关键问题是出现意外行为和可维护性问题的潜力,尤其是在现场词典更新(`| =`)的情况下。讨论涉及有关Python的语法,Mustability和添加新功能和保持可读性之间的权衡的更广泛观点。有些人争辩说清洁数据结构,例如数据类别,而另一些人则指出了词典在处理关键字参数之类的任务中的实用性。确认原始帖子的顽皮性质,并警告说,它可以使用它用于生产代码。
相关文章

原文

mom can we have dict unpacking in python?

no seriously. I do not need another joke package of mine to be deemed "critical" to pypi 1

  1. pip install dict-unpacking-at-home
  2. add # -*- coding: dict-unpacking-at-home -*- to the top of your file (second line if you have a shebang)
  3. enjoy!
# -*- coding: dict-unpacking-at-home -*-

dct = {'greeting': 'hello', 'thing': 'world'}

{greeting, thing} = dct
print(greeting, greeting, thing)  # hello hello world

# even with nesting!
dct = {'a': [1, 2, 3]}
{'a': [1, *rest]} = dct
print(rest)  # [2, 3]

the current version breaks line numbers in stacktraces -- the correct-line-numbers branch has a fix. but at what cost.

see also please don't use this

  1. with almost a million downloads per month and 30M+ total

联系我们 contact @ memedata.com