On 05/06/2019 00:37, nathan tech wrote: > Hi there, > > So I have just fixed a huge bug in my program, but don't understand > exactly... How it bugged.
Neither do I, your explanation raises more questions than answers. > 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 Your terminology is odd here. You are not loading anything into knm, rather you are assigning the value of knm to the "feed" dictionary entry. > 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 Similarly this assigns the value of r to the "feed" entry - the same "feed" entry as for knm so you have now overwritten the knm value in the dictionary.. > 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. Sorry, I have no idea what you mean by that. Which is the "first loaded feed"? knm?, r or the feeds dictionary? And what is the "second loaded feed"? What do you mean by a "feed" in this context? You are setting g.feeds[link] to g.blank_feed in both cases. Your line g.feeds[link]["feed"]=r is exactly the same as if you typed g.blank_feed["feed"]=r If you set the knm and r variables to fixed integer values (say 42 and 666) that would allow you to tell us what variable has what value. And what you expected them to store. (The fact that knm and r may normally contain some other kind of object is not relevant to this question.) > 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. What works? What is different? I still don't know what you think should be happening, what is happening first time round, and what is now happening. > but why does it work? > > Why does that semi unlink all the variables? The semicolon should not "unlink all variables", whatever that means. But I have no idea what you are seeing so cannot comment any further. You need to give us more specifics. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor