Note that there are some explanatory texts on larger screens.

plurals
  1. POClass variable dictionary not saving with pickle.dump in python 2.7
    primarykey
    data
    text
    <p>I am using pickle to save an object graph by dumping the root. When I load the root it has all the instance variables and connected object nodes. However I am saving all the nodes in a class variable of type dictionary. The class variable is full before being saved but after I unpickle the data it is empty.</p> <p>Here is the class I am using:</p> <pre><code>class Page(): __crawled = {} def __init__(self, title = '', link = '', relatedURLs = []): self.__title = title self.__link = link self.__relatedURLs = relatedURLs self.__related = [] @property def relatedURLs(self): return self.__relatedURLs @property def title(self): return self.__title @property def related(self): return self.__related @property def crawled(self): return self.__crawled def crawl(self,url): if url not in self.__crawled: webpage = urlopen(url).read() patFinderTitle = re.compile('&lt;title&gt;(.*)&lt;/title&gt;') patFinderLink = re.compile('&lt;link rel="canonical" href="([^"]*)" /&gt;') patFinderRelated = re.compile('&lt;li&gt;&lt;a href="([^"]*)"') findPatTitle = re.findall(patFinderTitle, webpage) findPatLink = re.findall(patFinderLink, webpage) findPatRelated = re.findall(patFinderRelated, webpage) newPage = Page(findPatTitle,findPatLink,findPatRelated) self.__related.append(newPage) self.__crawled[url] = newPage else: self.__related.append(self.__crawled[url]) def crawlRelated(self): for link in self.__relatedURLs: self.crawl(link) </code></pre> <p>I save it like such:</p> <pre><code>with open('medTwiceGraph.dat','w') as outf: pickle.dump(root,outf) </code></pre> <p>and I load it like such:</p> <pre><code>def loadGraph(filename): #returns root with open(filename,'r') as inf: return pickle.load(inf) root = loadGraph('medTwiceGraph.dat') </code></pre> <p>All the data loads except for the class variable __crawled.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload