Message110470
| Author |
pitrou |
| Recipients |
alexandre.vassalotti, amaury.forgeotdarc, barry, belopolsky, benjamin.peterson, mark.dickinson, nnorwitz, pitrou, terry.reedy, tim.peters |
| Date |
2010年07月16日.18:39:23 |
| SpamBayes Score |
1.8085143e-06 |
| Marked as misclassified |
No |
| Message-id |
<1279305566.24.0.0133539323324.issue3657@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
It should be noted that, contrary to Amaury's suggestion, pickling random.seed fails under 3.x:
>>> pickle.dumps(random.seed)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/antoine/py3k/__svn__/Lib/pickle.py", line 1314, in dumps
Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'method'>: attribute lookup builtins.method failed
Furthermore, the original problem can also be reproduced under 3.x, using Amaury's trick:
>>> pickle.dumps(random.random)
b'\x80\x03crandom\nrandom\nq\x00.'
>>> list(sys.modules.values())[0].random = random.random
>>> pickle.dumps(random.random)
b'\x80\x03cheapq\nrandom\nq\x00.'
I think a possible heuristic in whichmodule() would be, if __module__ is not found or None, to look for a __module__ attribute on __self__:
>>> random.random.__module__
>>> random.random.__self__.__module__
'random' |
|