_sitebuiltins?

Chris Angelico rosuav at gmail.com
Sun Sep 24 21:49:14 EDT 2017


On Mon, Sep 25, 2017 at 11:39 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Chris Angelico <rosuav at gmail.com> writes:
>>But if anything got imported from somewhere else, you get the
>>_original_ source, not the one you got it from:
>>>>> from ssl import namedtuple
>>>>> namedtuple.__module__
>>'collections'
>>Is that good enough for what you need? It's not "where did this come
>>from", but it's "where does this live".
>
>   The problem with »__module__« is that it is not always
>   a permissible prefix for a use of the name. For example,
>
> |>>> import builtins
> |
> |>>> import _sitebuiltins
> |
> |>>> help.__module__
> |'_sitebuiltins'
> |
> |>>> _sitebuiltins.help
> |AttributeError: module '_sitebuiltins' has no attribute 'help'
> |
> |>>> builtins.help
> |Type help() for interactive help, or help(object) for help about object.
>
>   So, I am looking for something that gives me »builtins«
>   in the case of »help«.

Here's where that object comes from:

def sethelper():
    builtins.help = _sitebuiltins._Helper()

So, you're out of luck - nothing's going to point to builtins.

Why do you need this? Can you, perhaps, just check the builtins for
the name? Or for the object (`help in builtins.__dict__.values()`)?

ChrisA



More information about the Python-list mailing list