jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Could not make Pickle work #228

Closed villares closed 6 years ago

villares commented 6 years ago

Hi, maybe it's me but this is giving an error:

import pickle

A = "to be saved"
pickle.dump(A, open("variableA.p", "wb"))
A = "temp value"
print A
pickle.load(open("variableA.p", "rb"))
print A

The error is:

processing.app.SketchException: EOFError
    at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:244)
    at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:125)
    at java.lang.Thread.run(Thread.java:748)
jdf commented 6 years ago

I'm guessing it's because you're not closing the file.

villares commented 6 years ago

No error now :) But it doesn't work (or I don't understand what I'm doing) :(

import pickle

A = ["to be saved"]
f = open("variableA.p", "wb")
pickle.dump(A, f)
f.close()

A = ["temp value"]
print A

f =  open("variableA.p", "rb")
pickle.load(f)
print A
f.close()

PS: I've tried the more elegant with open( ... ) as f: thing too

jdf commented 6 years ago

A = pickle.load(f)

villares commented 6 years ago

Thank you!!!