On Wed, 12 Oct 2016, 3:51 AM <s...@weacceptyou.com> wrote:

> yo sorry,
>
> i mean theres a function in a module that i call. i meant after the
> function in a module creates a variable, is the next time that function is
> called the variable created previously is no longer existing?.
>
> but i guess you already answered it. Though im not sure what the stack
> frame thing is.
>

Cool, thank you for clarifying.
Yes the variable will be gone when the call to the function ends.

When you call a function, some memory is allocated, so hold the variables
that you newly create within that function. This is called "stack space".
If you have ever heard of a stack overflow, it is when you consume more
memory than was allocated for your functions stack space, and you crash.
In python, a thing called a stack frame is created and put into a list with
all of the other functions that are callers before you. That is,  if a()
calls b() and b()  calls c(), your stack would look like :

[..., a_frame, b_frame, c_frame]

This can actually be inspected from the "inspect" module, and is also how
tracebacks (crashes) know that history of where you are in code.

Ok so all those details aside, in summary, stack is where those local
function variables live, and the stack space for the function dies when the
function scope is over. Of you want any of that data to live on, then it
either needs to be returned or stored on an object that will continue to
live (class instance, global module scope, ...)



> thanks guys,
> Sam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/ef9b0e05-f8dc-40ce-837d-97110667a6a3%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1pq6J9eTxs%2B77jhUCg-6sWhaeHsZr618Gup%2B1Y5zgwaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to