[Tutor] would someone please explain this concept to me

nathan tech nathan-tech at hotmail.com
Tue Jun 4 19:37:23 EDT 2019


Hi there,

So I have just fixed a huge bug in my program, but don't understand 
exactly... How it bugged.

Confused?

I sure was.

Here's some code:

globals.py:

feeds={}

blank_feed={}

blank_feed["checked"]=1

blank_feed["feed"]=0


main file:

import globals as g

# some code that loads a feed into the variable knm

g.feeds[link]=g.blank_feed;

g.feeds[link]["feed"]=knm

#in the below code, the variable link has a different value:

# load a feed into the variable r

g.feeds[link]=g.blank_feed

g.feeds[link]["feed"]=r


Now at this point, python would set the first loaded feed to the same 
thing as the second loaded feed. It also set g.blank_feed to the second 
feed, as well.

I replaced the last three lines with this:

# load a feed into the variable r

g.feeds[link]=g.blank_feed;

g.feeds[link]["feed"]=r

And it works.

but why does it work?

Why does that semi unlink all the variables?

Thanks

Nathan



More information about the Tutor mailing list