<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The Internals of Python&#8217;s IMPORT_NAME Bytecode</title>
	<atom:link href="http://www.deskchecked.com/2008/04/14/the-internals-of-pythons-import_name-bytecode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deskchecked.com/2008/04/14/the-internals-of-pythons-import_name-bytecode/</link>
	<description>Thomas Lee's programming blog</description>
	<lastBuildDate>Sat, 27 Mar 2010 16:01:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Brett</title>
		<link>http://www.deskchecked.com/2008/04/14/the-internals-of-pythons-import_name-bytecode/comment-page-1/#comment-1054</link>
		<dc:creator>Brett</dc:creator>
		<pubDate>Mon, 14 Apr 2008 18:47:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.vector-seven.com/?p=59#comment-1054</guid>
		<description>The fromlist is needed by __import__ to perform potential imports if the module being imported is a package. Consider importing pkg/__init__.py as ``from pkg import stuff``. Stuff is expected to be a module, either pkg/stuff.py or pkg/stuff/__init__.py . __import__ handles this import and then sets the module as an attribute on the pkg module itself.

I know it seems convoluted, but it helps keep the bytecode simple.</description>
		<content:encoded><![CDATA[<p>The fromlist is needed by __import__ to perform potential imports if the module being imported is a package. Consider importing pkg/__init__.py as &#8220;from pkg import stuff&#8220;. Stuff is expected to be a module, either pkg/stuff.py or pkg/stuff/__init__.py . __import__ handles this import and then sets the module as an attribute on the pkg module itself.</p>
<p>I know it seems convoluted, but it helps keep the bytecode simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Bonser</title>
		<link>http://www.deskchecked.com/2008/04/14/the-internals-of-pythons-import_name-bytecode/comment-page-1/#comment-1053</link>
		<dc:creator>Paul Bonser</dc:creator>
		<pubDate>Mon, 14 Apr 2008 17:42:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.vector-seven.com/?p=59#comment-1053</guid>
		<description>Thanks for the response, Thomas. Somehow at 2AM it doesn&#039;t always occur to me to do the obvious thing like look at the Python documentation.

After looking at the docs for __import__, it&#039;s interesting to see that the values in fromlist aren&#039;t actually used, but it is significant whether the fromlist is empty or non-empty.

&lt;blockquote&gt;
When the name variable is of the form package.module, normally, the top-level package (the name up till the first dot) is returned, not the module named by name. However, when a non-empty fromlist argument is given, the module named by name is returned. This is done for compatibility with the bytecode generated for the different kinds of import statement; when using &quot;import spam.ham.eggs&quot;, the top-level package spam  must be placed in the importing namespace, but when using &quot;from spam.ham import eggs&quot;, the spam.ham subpackage must be used to find the eggs variable.
&lt;/blockquote&gt;

I suppose the reason that fromlist isn&#039;t just changed to a boolean is that it might be significant in a setup where __import__ is redefined for custom importing, like you said.</description>
		<content:encoded><![CDATA[<p>Thanks for the response, Thomas. Somehow at 2AM it doesn&#8217;t always occur to me to do the obvious thing like look at the Python documentation.</p>
<p>After looking at the docs for __import__, it&#8217;s interesting to see that the values in fromlist aren&#8217;t actually used, but it is significant whether the fromlist is empty or non-empty.</p>
<blockquote><p>
When the name variable is of the form package.module, normally, the top-level package (the name up till the first dot) is returned, not the module named by name. However, when a non-empty fromlist argument is given, the module named by name is returned. This is done for compatibility with the bytecode generated for the different kinds of import statement; when using &#8220;import spam.ham.eggs&#8221;, the top-level package spam  must be placed in the importing namespace, but when using &#8220;from spam.ham import eggs&#8221;, the spam.ham subpackage must be used to find the eggs variable.
</p></blockquote>
<p>I suppose the reason that fromlist isn&#8217;t just changed to a boolean is that it might be significant in a setup where __import__ is redefined for custom importing, like you said.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
