2012/5/20, Nicolas M. Thiery <nicolas.thi...@u-psud.fr>: > On Sun, May 20, 2012 at 11:07:16AM +0200, Vincent Delecroix wrote: >> Hello, >> >> > On Fri, May 18, 2012 at 07:36:51AM -0700, Frédéric Chapoton wrote: >> >> trying to test my own files on sage 5.0, it seems that it takes many >> >> import statements. Some of them behave strangely : >> >> >> >> sage: import_statements(euler_phi) >> >> from sage.rings.arith import Number of positive integers <=n but >> >> relatively prime to n >> >> >> >> sage: import_statements(QQ) >> >> from sage.rings.rational_field import Rational Field >> >> Now with import_statements-vd.patch applied >> >> {{{ >> sage: import_statements(euler_phi) >> from sage.rings.arith import euler_phi >> sage: import_statements(QQ) >> from sage.all import QQ >> }}} >> >> The hack is very weak (uses find and grep from the shell) but mainly >> works. Feel free to improve. > > Thanks! > > Now that I think about it, here is a variant to recover the name under > which the object is stored in its module: > > sage: module = sys.modules[euler_phi.__module__] > sage: [key for key in module.__dict__ if module.__dict__[key] == > euler_phi] > ['euler_phi'] > > Of course it's not robust if the object has an alias in this > module. And if the object is stored in a module while its class is > defined in a different module. >
In particular sage: sage: module = sys.modules[ZZ.__module__] sage: [key for key in module.__dict__ if module.__dict__[key] == ZZ] [] Do the following is more "safe"? 1) treat the case of the object being a module itself 2) try to see if the object is defined in the same module as its class (what Nicolas suggested) 3) make a lazy search using globals() and find/grep (what I wrote in the patch) the case of euler_phi is done with 2) while the case of ZZ is done with 3). Remains the problems of aliases... any concrete example? Vincent -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-devel@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.