使函数定义的顺序无关紧要 [英] make order of function definitions irrelevant
问题描述
您好,
根据
http://mail.python.org/pipermail/tut...ly/007246.html
函数定义的顺序在python中很重要。有没有人
知道一个避免这个的伎俩?有没有办法声明?函数
没有定义它们?
(使函数定义的顺序无关紧要对于自动生成的python脚本是有用的。
。 )
J?rg
" Joerg Schuster" < js@cis.uni-muenchen.de>在消息中写道
news:cr ************* @ pinatubo.cis.uni-muenchen.de ...你好,
http://mail.python.org/pipermail/tut...ly/007246.html
函数定义的顺序在python中很重要。有没有人知道一个避免这个的伎俩?有没有办法声明?函数
没有定义它们(
(使函数定义的顺序无关紧要对于自动生成的python脚本是有用的。)
你所看到的是一个模块的执行顺序是
加载。据我所知,这不会改变,而且我不会看到任何理由改变它。
如果你会告诉我们一些你看到的应用程序
a需要这个,也许我们可以提出一些建议。
John Roth
J?rg
Joerg Schuster写道:
依据
http:/ /mail.python.org/pipermail/tut...ly/007246.html
函数定义的顺序在python中很重要。有没有人知道一个避免这个的伎俩?有没有办法声明?函数
没有定义它们(
(使函数定义的顺序无关紧要对自动生成的python脚本很有用。)
>
你不能在定义之前调用*函数:
fun()
def fun():传递
会窒息。但是没有问题
def first():second()
def second():传递
所以我看不出这可能成为脚本生成的障碍。
你能提供一个例子吗?
Peter
Joerg Schuster写道:
http://mail.python.org/pipermail/tut...ly/007246.html >
函数定义的顺序在python中很重要。有没有人知道一个避免这个的伎俩?
No.
有没有办法声明?功能没有定义它们?
No.
(使函数定义的顺序无关紧要对自动生成的python脚本很有用。)
不,它不会。
基本上,你认为这里的问题不是问题
实际上实践。您可以向Python-the-language添加声明,
但是在实际调用函数之前它们是无关紧要的。
调用函数时,它必须有已经定义了(不仅仅是宣布了
),因此声明完全是多余的。
-Peter
Hello,
according to
http://mail.python.org/pipermail/tut...ly/007246.html
the order of function definitions does matter in python. Does anyone
know a trick to avoid this? Is there a way to "declare" functions
without defining them?
(Making the order of function definitions irrelevant would be useful
for automatically generated python scripts.)
J?rg
"Joerg Schuster" <js@cis.uni-muenchen.de> wrote in message
news:cr*************@pinatubo.cis.uni-muenchen.de...Hello,
according to
http://mail.python.org/pipermail/tut...ly/007246.html
the order of function definitions does matter in python. Does anyone
know a trick to avoid this? Is there a way to "declare" functions
without defining them?
(Making the order of function definitions irrelevant would be useful
for automatically generated python scripts.)
What you''re seeing is the order of execution as a module is
loaded. As far as I can tell, that''s not going to change, and I don''t
see any reason to change it.
If you would tell us a bit about the application where you see
a need for this, maybe we could make some suggestions.
John Roth
J?rg
Joerg Schuster wrote:
according to
http://mail.python.org/pipermail/tut...ly/007246.html
the order of function definitions does matter in python. Does anyone
know a trick to avoid this? Is there a way to "declare" functions
without defining them?
(Making the order of function definitions irrelevant would be useful
for automatically generated python scripts.)
You cannot *call* a function before it is defined:
fun()
def fun(): pass
will choke. But there is no problem with
def first(): second()
def second(): pass
So I cannot see where this could be an obstacle to script generation.
Could you provide an example?
Peter
Joerg Schuster wrote:
according to
http://mail.python.org/pipermail/tut...ly/007246.html
the order of function definitions does matter in python. Does anyone
know a trick to avoid this?
No.
Is there a way to "declare" functions without defining them?
No.
(Making the order of function definitions irrelevant would be useful
for automatically generated python scripts.)
No, it would not.
Basically, the problem you believe is here is not a problem
in actual practice. You could add declarations to Python-the-language,
but they''re irrelevant until the function is actually called.
When the function is called, it has to have been defined (not just
declared) and so the declaration would be completely redundant.
-Peter
这篇关于使函数定义的顺序无关紧要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!