Using class without importing module
Josiah Carlson
jcarlson at nospam.uci.edu
Tue Feb 10 17:50:29 EST 2004
Thomas Aanensen wrote:
> Hi all.
>
> I'm sending a class over a socket connection, and I want to use this class
> at the new location. The problem is that I get a "module blah does not
> exist" error.
>
> Is it possible for me to use this class without importing the module? How?
>
> Any other suggestions?
It sounds like you are using:
import Pickle
socketinstance.send(Pickle.dumps(classinstance))
The above doesn't work. Pickle only encodes the data associated with
that class, not the bytecode required for the functionality. It refers
to the module.class reference to deal with reconstructing it later from
the pickle.
In general, you do need to import the module in order to use the class.
- Josiah
More information about the Python-list
mailing list