Cheetah automatically detects functions and methods in Cheetah $variables and calls them if the parentheses have been left off. Our previous example can be further simplified to:
$customers.kerr.address
As another example, if 'a' is an object, 'b' is a method
$a.b
is equivalent to
$a.b()
If b returns a dictionary, then following variations are possible
$a.b.c --OR-- $a.b().c --OR-- $a.b()['c']
Further notes:
self
for methods) or to provide default values for all arguments.
If the function requires arguments, you must use the ()
.
$myInstance.fname
. Do we want to look up fname
in the namespace
of myInstance
or in the namespace of whatever myinstance
returns?
It could go either way, so Cheetah follows the principle of least surprise. If
you do want to call the instance, put the ()
on, or rename the
.__call__()
method to .__str__
.
$getVar('varName', 'default value', False)
. (.getVar()
works
only with searchList values.)