Having trouble importing C# interface into Python
Question: I've been doing a bunch of searching and reading today, and haven't figured
out the right way to implement something, or even determining if it's
possible.

Here's the gist of what I'm attempting right now. I have an application that
loads plugins via MEF. Plugins can implement a variety of interfaces, and
let's say I have one called `IDevice`. I had this wacky idea that maybe a user
would want to write his own Device plugin in IronPython, and his IronPython
would just have to inherit from `IDevice` and implement the requisite methods.

Now I know it's possible to implement the interface in IronPython by defining
a class like this:

    
    
    class MyDevice(IDevice):
      pass
    

But I can't get past the first problem -- what's the correct way to import the
interface?

The IDevice interface is defined in a separate assembly called
MyInterfaces.dll like this:

    
    
    namespace Company.Shared.MyInterfaces
    {
        public interface IDevice
        {
            string GetName();
        }
    }
    

I've tried `import MyInterfaces` since that's the most logical thing, but that
didn't work. I also tried many less logical combinations of `import`s and
`from`s. I always get the following error:

    
    
    ImportException occurred
    No module named MyInterfaces
    

I loaded Process Monitor to see what my app was trying to load when I executed
my script, and it was trying to load a file called MyInterfaces, and then
would try to load MyInterfaces.py. Well, the file is called
MyInterfaces*_.dll_ *, so I changed my import statement to read `import
MyInterfaces.dll`, but that had no effect -- my code would still just try to
load a file called MyInterfaces. I have confirmed that all of my dependencies
are in the right folder.

I feel super lame for not being able to figure this out, so I'm hoping that
someone can point me in the right direction. Thank you!


Answer: I believe the correct approach would be:

    
    
    import clr
    clr.AddReference('MyInterfaces')
    
    from Company.Shared.MyInterfaces import IDevice
    

