A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-November/083750.html below:

[Python-Dev] __import__ problems

[Python-Dev] __import__ problems [Python-Dev] __import__ problemsNick Coghlan ncoghlan at gmail.com
Fri Nov 28 12:48:51 CET 2008
Mart Somermaa wrote:
>>> The variant proposed by Hrvoje Niksic:
>>>
>>>  >>> __import__(modname)
>>>  >>> mod = sys.modules[modname]
>>>
>>> looks more appealing, but comes with the drawback that sys has to be
>>> imported for that purpose only.
>>
>> That is not a real drawback, as "sys" will certainly be present in the
>> system, so the "importing" boils down to a dict lookup and a variable
>> assignment.
> 
> I meant that you have to
> 
>>>> import sys
> 
> only to access sys.modules (i.e. importing sys may not be necessary
> otherwise).

As Hrvoje has pointed out, 'sys' is part of the internal interpreter
machinery - it's there as soon as the interpreter starts. The import
call for it just grabs it out of the module cache and creates a
reference to it in the current namespace.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4