why import plugins used exec instead of __import__?

Robert Collins robertc at robertcollins.net
Tue Jun 17 07:01:57 BST 2008

On Tue, 2008-06-17 at 08:41 +0300, Alexander Belchenko wrote:
> Ah, I found it. __import__ allows to import any file even with non-valid python name,
> while exec "import foo-bar" will produce Syntax Error.
> Sorry for noise email.

Another difference is the amount of code. Using __import__ correctly
(making the plugin available as a module after it is loaded, handling
various errors, mapping the asked for module to the actual thing to
pass) is very complex. So using exec is much less code to duplicate from
the python standard library, and the result is less maintenance and
fewer things to go wrong.

GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20080617/34c9ad82/attachment.pgp 

More information about the bazaar mailing list