Iron Python – Importing Modules

I have been playing around with Iron Python, and it’s a joy. Mostly it’s a joy because I don’t have to look at curly braces all day, but I can do a lot of the same stuff I could do with C#.

But I learned the hard way (and I guess I should’ve known) that:

import module

is not the same as

from module import *

I was working on the example in ProIronPython (Apress) Chapter 5 (if you care to know), and was instructed to  import the module (page 102, bottom). So I tried using version 1 (above), and got an error upon building, more specifically an ArgumentType Exception in this line of


The message read: module object is not callable. – – – There is lots of information about importing modules in IronPython on this page here. But the real help came from the Python help pages: “Chapter 6.12 The import Statement“. Even if you don’t know much about modules, the error message leads you in the right direction. Turns out it’s all about namespaces.

Quoting from


The first form of import statement binds the module name in the local namespace to the module object…  The from form does not bind the module name: it goes through the list of identifiers, looks each one of them up […], and binds the name in the local namespace to the object thus found.


Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s