How can I use my 'namedtuple' structure with 'pickle'?
<p>I have created  tuple of  dictionary using </p>

<pre><code>from collections import namedtuple
import random
demand={}
Site_Product=namedtuple("Site_Product", ["site", "product"])   
Products=['P1','P2','P3']    
for P in Products:
    for node in range(1,4): #Suppliers:
        sp=Site_Product(site=node, product=P)
        demand={sp:random.normalvariate(30, 25)}
</code></pre>

<p>Then I want to save these in case I might use it later on as follows:</p>

<pre><code>import pickle
PIK = "pickle_SC_detail.dat"  
with open(PIK, "wb") as f:
    pickle.dump(demand, f)
</code></pre>

<p>I got a bunch of errors mainly pointing to my namedtuple structure:</p>

<pre><code>  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 1376, in dump
    Pickler(file, protocol).dump(obj)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 224, in dump
    self.save(obj)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 655, in save_dict
    self._batch_setitems(obj.iteritems())

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 668, in _batch_setitems
    save(k)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 401, in save_reduce
    save(args)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 568, in save_tuple
    save(element)

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self

  File "C:\Users\Ozgu\Anaconda2\lib\pickle.py", line 754, in save_global
    (obj, module, name))

PicklingError: Can't pickle \&lt;class '__main__.Site_Product'\&gt;: it's not found as __main__.Site_Product
</code></pre>

<p><strong>Is there a  work around either for keeping my dict of tuple(for keys) or recording my data in an inexpensive manner, so that they will coexist?</strong></p>