没有括号的函数 [英] functions without parentheses

查看:96
本文介绍了没有括号的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有可能创建一个可以使用

而不用括号括起来的函数?例如,


def检查(str):

.....

.....


有没有办法定义它以便我可以调用它

喜欢


检查" string"

而不是检查(" string")?


提前谢谢


-Jerry


__________________________________________________ __

用Yahoo!开始新的一天 - 将其设为主页
http://www.yahoo.com/ r / hs

Hi,
Is it possible to create a function that you can use
without parenthesizing the arguments? for example, for

def examine(str):
.....
.....

Is there some way to define it so that I can call it
like

examine "string"
instead of examine("string")?

thanks in advance

-Jerry

__________________________________________________ __
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

推荐答案

2005年7月28日星期四00:59:51 -0700,Jerry He写道:
On Thu, 28 Jul 2005 00:59:51 -0700, Jerry He wrote:

是否可以创建一个可以使用
而不用括号括起来的函数?
Hi,
Is it possible to create a function that you can use
without parenthesizing the arguments?




你想解决的问题是什么,需要这种语法,

为什么不能用括号解决?


-

史蒂文。



What problem are you trying to solve that requires this sort of syntax,
and why can''t it be solved with parentheses?

--
Steven.


如果你真的想要那种语法,那你为什么不用Visual? br />
基本? ;)

If you actually want that kind of syntax, then why don''t you use Visual
Basic? ;)


Simon Dahlbacka写了[关于没有括号的函数调用]:
Simon Dahlbacka wrote [about function calls without parenthesis]:
如果你真的想要那种语法,那么你为什么不用Visual
Basic? ;)
If you actually want that kind of syntax, then why don''t you use Visual
Basic? ;)



因为Perl太诱人而无法忽视。


然而,OP问题的严肃答案是Python拒绝

来猜测函数引用后面没有左括号

是对函数的引用还是对调用
$的结果的引用b $ b功能。 Perl和VB(脚本)更多地利用上下文,使得b / b $ b混淆了许多用户。


有人尝试的时间


导入此


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC http: //www.holdenweb.com/


Because Perl is far too tempting to ignore.

The serious answer to the OP''s question, however, is that Python refuses
to guess whether a function reference not followed by a left parenthesis
is a reference to a function or a reference to the result of calling the
function. Perl and VB(Script) make more use of context, in ways that
confuse many users.

Time for someone to try

import this

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/


这篇关于没有括号的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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