title: base64 encoding vs pickling on python objects
body: <p>I have not used pickling and encoding much with Python. But, just as I came to know about them, I was thinking that I could perform the same operation of converting a python object to a string using 2 different ways.</p>
  
  <p><strong>#1:</strong> Using pickle module</p>
  
  <pre><code>&gt;&gt;&gt; encoded = pickle.dumps(range(10))
  &gt;&gt;&gt; pickle.loads(encoded)
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  </code></pre>
  
  <p><strong>#2:</strong> Using Base64 Encoding</p>
  
  <pre><code># First I'l define encode and decode functions for convenience.
  
  def encode(obj):
      string = json.dumps(obj)
      return base64.b64encode(string)
  
  def decode(string):
      decoded_string = base64.b64decode(string)
      return json.loads(decoded_string)
  
  # Encode and Decode.
  &gt;&gt;&gt; encoded = encode(range(10))
  &gt;&gt;&gt; decode(encoded)
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  </code></pre>
  
  <p>base64</p>
  
  <p>What are their typical use cases and which method is more efficient in its performance?</p>
  
  <h3>UPDATE:</h3>
  
  <p>I understand now that my question does not make much sense. Comparing <code>json</code> and <code>pickle</code> would be a better question. Base64 encoding can be performed on both json or pickled strings and is used for creating an ASCII only string encoding; example: for passing data as GET parameter in urls.</p>