On 2/1/07, tomer filiba <[EMAIL PROTECTED]> wrote: > i've had some difficulty with code that attempts to locate a type > by its __module__ and __name__, something like: > getattr(sys.modules[t.__module__], t.__name__) > > the trouble is, all builtin types claim to belong to the __builtin__ module. > for example: > >>> types.FunctionType > <type 'function'> > >>> types.FunctionType.__name__ > 'funcrtion' > >>> types.FunctionType.__module__ > '__builtin__' > > but -- > >>> __builtin__.function > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'module' object has no attribute 'function' > > most, but not all, of the types are exposed in __builtin__... this required > me to create an artificial mapping in which "__builtin__.function" is mapped > to types.FunctionType, and then use this mapping instead of sys.modules, > which adds more special cases on my part. >
This has come up before on python-dev, IIRC. Double-check the archives. -Brett _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
