Variables defined in a function - Python
Question: I am running this code: <https://dpaste.de/RiAP>

As you see, the variable `linespecificpayload` is used only within this
function, but if I check the ID, its the same in every function call.

I can't seem to figure out how to flush its value with each call. Both the
call for `id(linespecificpayload)` return the same value. Any suggestions
would be welcome.

Also the code is something I wrote in an hour or two. So may not be the most
efficient one.


Answer: The reason is that you are assigning a global object to `linespecificpayload`,
thus the reference stays the same.

If you would like to create a copy of the `filespecificpayload` dict you can
either:

  * use `filespecificpayload.copy()`. This will create a copy of the dict, but the values that existed before copying will be shared so that `id(filespecificpayload[key]) == id(filespecificpayload.copy()[key])`

  * use `copy.deepcopy()`:
    
        >>> from copy import deepcopy
    >>> d = deepcopy(filespecificpayload)
    >>> id(d[key]) == id(filespecificpayload[key])
    False
    

