title: Inspecting a pickle dump for dependencies
body: <p>Suppose I write the following code:</p>
  <pre class="lang-py prettyprint-override"><code>import pickle
  def foo():
      return 'foo'
  
  def bar():
      return 'bar' + foo()
  
  pickle.dump(bar, open('bar.bin', 'wb'))
  </code></pre>
  <p>At this point, I've a binary dump (of course without the dependency of <code>foo</code> from the global scope). Now, if I run the following line</p>
  <p><code>temp = pickle.load(open('bar.bin', 'rb'))</code></p>
  <p>I get the following error, and it makes perfect sense after having read <a href="https://stackoverflow.com/questions/10048061/how-to-pickle-a-python-function-with-its-dependencies">this</a>.</p>
  <blockquote>
  <p>Error: AttributeError: Can't get attribute 'bar' on &lt;module '<strong>main</strong>' (built-in)&gt;</p>
  </blockquote>
  <p>This of course is a minimal example but I'm curious if there is a generalized way that I can inspect the dependencies needed to properly unpickle the pickle dump. A trivial solution would be to handle attribute errors (as in the above case), but can I do it programmatically?</p>