pickle - Python pickling after changing a module's directory -


I recently changed the directory layout of my program: Before that, all my modules were inside the "main" folder. Now, I have taken them to a directory in the name of the program, and put __init __.py to create a package.

Now I have a single. My main directory is used to launch my program, which is very cheap.

Still, the attempt to load spicy files from previous versions of my program is failing. I'm getting, "Import Errotor: Tool's No Name Module" - which I think is because my module was in the first main folder, and now it's in whyteboard.tools, not just plain device, however, in the tool tool module Importing is in the same directory, so I suspect that the package needs to be specified.

Then, my program directory looks something like this:

Why-board -0.39.4

- & Gt; Why

- & gt; CHANGELOG.txt

/ P>

----> Why the Board /

---- > Why board / __init __ Py

----> Why board / gui.py

----> Why the board / tools.py

launches a block of code from whyteboard.py whyteboard / gui.py, which removes the GUI. This salty issue was certainly not happening before rearranging the directory. As is said, saving and restoring square frequency (in fact a function), you have to Some odds have to be respected:

Pickle classes can save and restore examples, although the class definition should be importable and imported as the same code when the object was stored < / P>

whyteboard.tools not "same module" as " device (even if it can be imported by the other module in the same package by the import tool , this is in sys.modules in sys .modules ['Whyteboard.tools'] : This is absolutely important, otherwise the same packages end up with one more many possibly controversial entries in one package in one package!).

If your pickle files are good / in the advice nose format (old ASCI format Pipri, which is the default only for the reasons for compatibility), once you make such changes, migrating them can actually be very trivial in the form of "file editing" (which is binary and c. ..!), Despite the suggestion of one more reply, I suggest, instead, you make a little "pickle script": it patch sys.modules in this way .. .:

  Why to import Import tool sys.modules ['Tools'] = Tools  

and then cPickle.load each file, del sys.modules ['Tools'] , and cPickle.dump back in each loaded object file: Temporary additional entry in sys.modules should pick up the pickles successfully, then dump them again Should use the correct module-name for sections of the examples (it should be ensured by deleting that additional entry).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -