Save non-pickleable variable?

Israel Brewster israel at ravnalaska.net
Fri Oct 20 13:19:16 EDT 2017


tldr: I have an object that can't be picked. Is there any way to do a "raw" dump of the binary data to a file, and re-load it later?

Details: I am using a java (I know, I know - this is a python list. I'm not asking about the java - honest!) library (Jasper Reports) that I access from python using py4j (www.py4j.org <http://www.py4j.org/>). At one point in my code I call a java function which, after churning on some data in a database, returns an object (a jasper report object populated with the final report data) that I can use (via another java call) to display the results in a variety of formats (HTML, PDF, XLS, etc). At the time I get the object back, I use it to display the results in HTML format for quick display, but the user may or may not also want to get a PDF copy in the near future. 

Since it can take some time to generate this object, and also since the data may change between when I do the HTML display and when the user requests a PDF (if they do at all), I would like to save this object for potential future re-use. Because it might be large, and there is actually a fairly good chance the user won't need it again, I'd like to save it in a temp file (tat would be deleted when the user logs out) rather than in memory. Unfortunately, since this is an object created by and returned from a java function, not a native python object, it is not able to be pickled (as the suggestion typically is), at least to my knowledge.

Given that, is there any way I can write out the "raw" binary data to a file, and read it back in later? Or some other way to be able to save this object? It is theoretically possible that I could do it on the java side, i.e. the library may have some way of writing out the file, but obviously I wouldn't expect anyone here to know anything about that - I'm just asking about the python side :-)

-----------------------------------------------
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------







More information about the Python-list mailing list