我一直在将对象腌制到文件系统,并在需要处理这些对象时读回它们。目前我有这个目的的代码。
def pickle(self, directory, filename):
if not os.path.exists(directory):
os.makedirs(directory)
with open(directory + '/' + filename, 'wb') as handle:
pickle.dump(self, handle)
@staticmethod
def load(filename):
with open(filename, 'rb') as handle:
element = pickle.load(handle)
return element
Run Code Online (Sandbox Code Playgroud)
现在我正在将我的应用程序(django)移动到Google应用程序引擎,并发现应用程序引擎不允许我写入文件系统。谷歌云存储似乎是我唯一的选择,但我无法理解如何将我的对象pickle为云存储对象并将它们读回以创建原始的python对象。