functions without parentheses

Delaney, Timothy (Tim) tdelaney at avaya.com
Thu Jul 28 04:07:30 EDT 2005


Jerry He wrote:

> def examine(str):
>      .....
>      .....
> 
> Is there some way to define it so that I can call it
> like
> 
> examine "string"
> instead of examine("string")?

No. Python's syntax does not work that way. Why would you want to? For
more information about this, read:

http://www.catb.org/~esr/faqs/smart-questions.html


You can create properties on classes which call a function when you get,
set or delete them. 

class Test (object):
    def _getX (self):
        return self.__x

    def _setX (self, value):
        self.__x = value

    x = property(fget=_getX, fset=_setX)

t = Test()
t.x = 1
print t.x

Note that this is almost completely different to what you asked about.

Tim Delaney



More information about the Python-list mailing list