Suhail
Suhail

Reputation: 2959

access variables of other functions

in python, how can i access the variables of one function into another function, is it possible, i tried the global variable method but that doesn't work for me.

can someone help me, how to access the variables from one function to another function.

Upvotes: 0

Views: 1705

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599630

Don't try to do this. Explicit is better than implicit - if your function needs access to certain variables, pass them in. If it needs to change a value in the calling function, return the new value.

Upvotes: 0

Dave Kirby
Dave Kirby

Reputation: 26552

If you want to share data between functions then create a class and turn the functions into methods on the class.

Upvotes: 1

Related Questions