tags:

views:

160

answers:

1

If I have a .Net class that is not part of any namespace then I'm not able to use it in ironpython.

Here is an example

Suppose I have a assembly FooLib.dll with the following class definition

//note the following class is not part of global namespace

public class Foo { }

Now I try to use it in ironpython

clr.AddReference("FooLib") # This call succeeds.

f = Foo()

The line f= Foo() returns the error

Traceback (most recent call last):

File "", line 1, in

NameError: name 'Foo' is not defined

I tried the following

from FooLib import *

f = Foo()

The line from FooLib import * reports an error which does make sense as the from clause should be used on namespaces and not assemblies

However, If the class Foo belong to some namespace, then i don't have a problem importing in ironpython

So, my query is how do I use a .net class belonging to a global namespace from ironpython

regards Ganesh

+1  A: 

You have to use a bare import like so:

import clr
clr.AddReference("FooLib") # This call succeeds.
import Foo
f = Foo()
Jeff Hardy
That works... thanks a lotGanesh
Ganesh