3

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 Answer 1

3

You have to use a bare import like so:

import clr
clr.AddReference("FooLib") # This call succeeds.
import Foo
f = Foo()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.