how does pickle know which to pick?
<p>I have my pickle function working properly</p>

<pre><code>    with open(self._prepared_data_location_scalar, 'wb') as output:
        # company1 = Company('banana', 40)
        pickle.dump(X_scaler, output, pickle.HIGHEST_PROTOCOL)
        pickle.dump(Y_scaler, output, pickle.HIGHEST_PROTOCOL)


    with open(self._prepared_data_location_scalar, 'rb') as input_f:
        X_scaler = pickle.load(input_f)
        Y_scaler = pickle.load(input_f)
</code></pre>

<p>However, I am very curious how does pickle know which to load? Does it mean that everything has to be in the same sequence?</p>

<p>What you have is fine.  It's a <a href="https://docs.python.org/2/library/pickle.html#pickle.Pickler" rel="nofollow">documented feature</a> of pickle:</p>

<blockquote>
  <p>It is possible to make multiple calls to the dump() method of the same Pickler instance. These must then be matched to the same number of calls to the load() method of the corresponding Unpickler instance. </p>
</blockquote>

<p>There is no magic here, pickle is a really simple stack-based language that serializes python objects into bytestrings.  The pickle format knows about object boundaries: by design, <code>pickle.dumps('x') + pickle.dumps('y')</code> is not the same bytestring as <code>pickle.dumps('xy')</code>. </p>

<p>If you're interested to learn some background on the implementation, <a href="http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/" rel="nofollow">this article</a> is an easy read to shed some light on the python pickler.</p>

python pickle