I'm trying to create a variable where when I call or use that variable, it runs a function to do stuff and return a certain variable. An example will make more sense:
def establish_client():
a = None
if True:
a = 'A'
return a
>>> print establish_client
'A'
It is possible to do this? Basically is there a way of running a method and returning something without using parenthesis?
Note: the following is a hack, and there's probably more than a good reason to not do it.
You can achieve something on that line using a
class
and the__str__()
method:Test:
Beware: it works only with print and functions that explicitly treat arguments as strings.
For example, if you want to assign its string value to another variable, you have to use
str(f)
so you end up using parentheses.