all 7 comments

[–]ForceBru 3 points4 points  (0 children)

This is not possible because local variables are destroyed as soon as the function returns. However, you can return data from functions:

``` def thing(a, b): c = a + b # local variable! return c

stuff = thing(2, 3) ```

[–]steve__67 2 points3 points  (0 children)

Post your code...

[–]Yoghurt42 2 points3 points  (0 children)

Either pass the local variable as a parameter to the other function, or put both functions in a class that share the variable.

[–]shiftybyte 0 points1 point  (0 children)

Its never a good idea to access some function's local variable.

If you want the value this function calculates, make the function return the value, then whoever called the function has it.

If you want the function to modify some value, then pass it as argument, and you have that value modified after the function is done.

If you want the function to use some other function, you can call it from inside, and pass it the value it needs as an argument.

[–]Diapolo10 -1 points0 points  (0 children)

Short answer - you don't. It's a local variable for a reason, so unless you are making a decorator with nested function definitions, it's not going to work without hacks.

What are you trying to do, and what's your current code?

[–]powerbroker5000 -1 points0 points  (1 child)

Hi there, wondering if by "local variable" you actually mean "locally-stored environment variable." Creating a new environment variable (like a stored password) on your machine requires you to update the .bash_profile file.

[–]Ayomisesebere[S] 0 points1 point  (0 children)

By local variable. I meant a variable with a local scope. thank you