def a((b,c,d),e): [英] def a((b,c,d),e):

查看:213
本文介绍了def a((b,c,d),e):的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pythonistas同志,


请查看

http://spyced.blogspot.com/2005/04/h...on-part-3 .html


如果你还没有这样做的话。看来您可以明确指定一个函数

来将n元组作为参数。它实际上是有效的,我自己检查了这个
。如果您阅读
的参考手册,请访问 http://docs.python .org / ref / function.html

非常小心,你会发现它确实是语言的一部分

spec,但它很可能最少宣传的Python的候选人

功能。难怪,因为它看起来像那些语言之一

特征使得暴行更容易实现一个数量级。


有没有人真正在实际代码中使用过它?


欢呼,

AdSR

解决方案

< blockquote>您可以随时解开元组,例如:


..>>> import sys

..>>> for(index,(key,value))in enumerate(sys.modules.iteritems()):

pass


AdSR写道:

Pythonistas同志,

请查看

http://spyced.blogspot.com/2005/04/h...on -part-3.html

如果你还没有这样做的话。看来您可以明确指定一个函数来将n元组作为参数。它确实有效,我自己检查了这个。如果您阅读
的参考手册,请访问 http://docs.python .org / ref / function.html
非常仔细,你会发现它确实是语言
规范的一部分,但它可能是最不广告的Python的候选者/>功能。

另请参阅inspect.getargs的来源,了解这使得

参数传递逻辑的复杂程度!

小奇迹因为它看起来像是那些使暴行变得容易一些的语言特征之一。

有没有人真正在实际代码中使用过它?


它出现在stdlib的少数几个地方,主要是测试:

#Search C:\Python23 \Lib

#Files * .py

#对于def [\ w] + \(\(

c:\ python23 \ lib\test \ test_compile.py(49)def comp_args((a,b)):

c:\ python23 \ lib\test\test_compile.py(53)def comp_args((a,b) =(3,4)):

c:\ python23 \lib \ test \ test_grammar.py(159)def f5((化合物,第一个),两个):传递

c:\ python23 \lib \ test\test_scope.py(318)def makeAddPair((a,b)):

c:\ python23 \ lib \ test \test_scope.py(319)def addPair((c,d)):

c:\ python23 \lib\site-packages \ wx-2.5.3-msw-ansi \ wx \ lib \ imageutils.py(36)def

makeGray((r,g,b),factor,maskColor):

c:\ python23 \ lib; \\ ccitb.py(82)def html((etype,evalue,etb),context = 5):

c:\\ python23 \lib; \\ cgitb.py(168)def text((etype,evalue,etb),context = 5):

c:\ python23 \lib \urlparse.py(118 )def urlunparse((scheme,netloc,url,params,

查询,片段)):

c:\ python23 \lib \urlparse.py(127) def urlunsplit((方案,netloc,网址,查询,

片段)):

干杯,

AdSR



" AdSR" < AR ********** @ yahoo.com>写道:

奇怪,因为它看起来像是那些语言特征之一
,使得暴行更容易犯下一个数量级。


eh?


def f((a,b)):

...





def f(tmp)的缩写:

a,b = tmp

...


如果你认为这是一个暴行,也许编程不适合你。

有没有人真正用它实际代码?




是的。 grep标准库,用于许多典型用例。


< / F>


Fellow Pythonistas,

Please check out

http://spyced.blogspot.com/2005/04/h...on-part-3.html

if you haven''t done so yet. It appears that you can specify a function
explicitly to take n-tuples as arguments. It actually works, checked
this myself. If you read the reference manual at
http://docs.python.org/ref/function.html
really carefully, you will find that it is indeed part of the language
spec, but it''s a likely candidate for the least advertised Python
feature. Small wonder since it looks like one of those language
features that make committing atrocities an order of magnitude easier.

Has anyone actually used it in real code?

Cheers,

AdSR

解决方案

You can always unpack a tuple that way, like in:

..>>> import sys
..>>> for (index, (key, value)) in enumerate(sys.modules.iteritems()):
pass


AdSR wrote:

Fellow Pythonistas,

Please check out

http://spyced.blogspot.com/2005/04/h...on-part-3.html

if you haven''t done so yet. It appears that you can specify a function
explicitly to take n-tuples as arguments. It actually works, checked
this myself. If you read the reference manual at
http://docs.python.org/ref/function.html
really carefully, you will find that it is indeed part of the language
spec, but it''s a likely candidate for the least advertised Python
feature.
See also the source of inspect.getargs for just how much this complicates the
argument-passing logic!
Small wonder since it looks like one of those language
features that make committing atrocities an order of magnitude easier.

Has anyone actually used it in real code?
It appears in a handful of places in the stdlib, mostly tests:
#Search C:\Python23\Lib
# Files *.py
# For def [\w]+\(\(
c:\python23\lib\test\test_compile.py(49) def comp_args((a, b)):
c:\python23\lib\test\test_compile.py(53) def comp_args((a, b)=(3, 4)):
c:\python23\lib\test\test_grammar.py(159) def f5((compound, first), two): pass
c:\python23\lib\test\test_scope.py(318) def makeAddPair((a, b)):
c:\python23\lib\test\test_scope.py(319) def addPair((c, d)):
c:\python23\lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\imageutils.py(36) def
makeGray((r,g,b), factor, maskColor):
c:\python23\lib\cgitb.py(82) def html((etype, evalue, etb), context=5):
c:\python23\lib\cgitb.py(168) def text((etype, evalue, etb), context=5):
c:\python23\lib\urlparse.py(118) def urlunparse((scheme, netloc, url, params,
query, fragment)):
c:\python23\lib\urlparse.py(127) def urlunsplit((scheme, netloc, url, query,
fragment)):

Cheers,

AdSR




"AdSR" <ar**********@yahoo.com> wrote:

Small wonder since it looks like one of those language features
that make committing atrocities an order of magnitude easier.
eh?

def f((a, b)):
...

is short for

def f(tmp):
a, b = tmp
...

if you think this is an "atrocity", maybe programming isn''t for you.
Has anyone actually used it in real code?



yes. grep the standard library for a number of typical use cases.

</F>


这篇关于def a((b,c,d),e):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆