Martin
Martin

Reputation: 905

Change package import name in python

I was wondering if it was possible to import a library in python, and completely change its name.

say i need to do :

import plop.blah.wii

but I want it to be recognized as foo.bar.yeah

something like

import plop.blah.wii as foo.bar.yeah

Any idea how can this be done ? When unpickling an object, Python expects a library that I have under plop.blah.wii, and I can't change that name .. but the pickle wants it to be foo.bar.yeah .

Thanks a lot for your help. Sorry for the confusion. It's been confusing me for a while now ..

Martin

Upvotes: 1

Views: 1140

Answers (1)

Geoff Reedy
Geoff Reedy

Reputation: 36071

Rather than aliasing the module, there's a way to more directly solve your problem. You can override the method used by the pickler to resolve globals to map the old module name to the new module name. The details are here.

Upvotes: 2

Related Questions