function without brackets ?

Sebastian 'lunar' Wiesner basti.wiesner at
Wed Jan 3 15:45:37 CET 2007

Stef Mientki <S.Mientki-nospam at> typed

> If I call a parameterless function without brackets at the end,
> the function is not performed, but ...

If you omit the brackets, you don't actually call the function. Instead
you get a reference to the function object.

Consider this example:

cwd = os.getcwd()
# cwd now contains a string, denoting the current working directory
func = os.getcwd
# func now contains a reference to the function os.getcwd
print func == os.getcwd # prints True
# you can even call it:
cwd_2 = func()
# cwd_2 now also contains a string with the current directory.
print cwd == cwd_2 # prints True, too

Freedom is always the freedom of dissenters.
                                      (Rosa Luxemburg)

More information about the Python-list mailing list