Bruce Christensen wrote: > Is something like the following close? Close, yes.
> if type(result) == tuple: > ... (do appropriate things here) > elif isinstance(result, basestring): > name = result > module = "<unknown module>" > try: > module = obj.__module__ > found_obj = getattr(sys.modules[module], name) > except AttributeError, KeyError: > raise PicklingError( > "Can't pickle %r: it's not found as %s.%s" > % (obj, module, name) > ) If obj has no __module__ attribute (or if it is None), pickle (didn't check cPickle) also does for n, module in sys.module.items(): if "module-ignored": continue if getattr(module, result, None) is obj: break # use n as module name If obj does have a __module__ attribute, it uses __import__ to import the module, just to make sure it gets into sys.modules. Otherwise, it looks correct. Regards, Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com