I have a scenario that can be implemented in multiple ways. I need suggestion which is more optimized / python way of implementing and why ?
lets consider nested function calls as funca1 -> funca2 -> funca3 ->funca4 funcb1 -> funcb2 -> funcb3 ->funcb4
if __name__ == "__main__":
funca1()
funcb1()
and varx variable is only used / or needed by funca4 and funcb3. then we have below options
This can also be achieved by creating class and assigning varx as property . But current design of the project doesn't allow this
I ran a demo code with the scenarios you gave, and timed the execution time using the time
module and obtained the following results:
Fastest Execution Rankings:
varx
as a global variable.varx
variable accross all the functions.