title: Reading and writing pickles using Google Cloud
body: <p>I want to read an existing pickle (that contains a dictionary) which is stored in a folder inside a Google Cloud Bucket. Then update the pickle after performing some functions, which is equal to overwriting the pickle.</p>
  
  <p>Traditionally I would do something like:</p>
  
  <pre><code>import pickle
  # Read pickle:
  pickle_in = open('dictionary.pickle','rb')
  my_dictionary = pickle.load(pickle_in)
  my_dictionary 
  
  # MODIFY DICTIONARY BY, FOR EXAMPLE, ADDING NEW REGISTERS
  
  # Overwrite pickle:
  pickle_out = open('dictionary.pickle','wb') 
  pickle.dump(my_modified_dictionary,pickle_out)
  pickle_out.close()
  </code></pre>
  
  <p>Now I need to do something similar but on Google Cloud. So I need to change the path of the file and use cloudstorage.open():</p>
  
  <pre><code>import pickle
  my_path = '/bucket_name/pickle_folder/my_dictionary.pickle'
  
  # Read pickle:
  pickle_in = cloudstorage.open(path,'r')
  my_dictionary = pickle.load(pickle_in)
  my_dictionary 
  
  # MODIFY DICTIONARY BY, FOR EXAMPLE, ADDING NEW REGISTERS
  
  # Overwrite pickle:
  pickle_out = cloudstorage.open(path,'w') 
  pickle.dump(my_modified_dictionary,pickle_out)
  pickle_out.close()
  </code></pre>
  
  <p>Will this work? <a href="https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/functions#open" rel="nofollow noreferrer">cloudstorage.open()</a> seems to be the equivalent to open(). But I am not sure that if I specify the path when dumping the pickle will actually overwrite the pickle on the specified folder.</p>