dynamic - Call a python variable that runs a function which returns a variable for the original python variable -


i'm trying create variable when call or use variable, runs function stuff , return variable. example make more sense:

def establish_client():     = none     if true:         = 'a'     return   >>> print establish_client 'a' 

it possible this? there way of running method , returning without using parenthesis?

in general case: no.

but there techniques might come close.

properties allow members in object.

class demo(object):     @property     def establish_client(self):         = none         if true:             = 'a'         return  d = demo() print d.establish_client 

but properties don't work local or global variables.

also can use __str__ string conversion, works when need behavior when variable used in way converts string. not case. see mescalinum answer how that.


Comments

Popular posts from this blog

python - How to create jsonb index using GIN on SQLAlchemy? -

PHP DOM loadHTML() method unusual warning -

c# - TransactionScope not rolling back although no complete() is called -