[IronPython] Problem with 3 modules, classes and missing attributes

Pjerrot janrou at gmail.com
Sun Apr 6 02:09:29 CEST 2008


I have problem understanding IronPython. The problem is here:

Traceback (most recent call last):
  File , line 0, in <stdin>##9
  File , line 0, in __import__##4
  File ..\NamespaceTest\program.py, line 28, in Initialize
  File ..\NamespaceTest\program.py, line 24, in start
  File ..\NamespaceTest\program.py, line 9, in testBar
AttributeError: type object 'ns2' has no attribute 'Bar'

I try to follow the namspace style created by Visual Studion
IronPython. A namspace is cerated as a class, without a constructor.
Inside the class is another class. The outer class works like a

I create two files each holding a class, Bar and Foo. The files start
with the same "class ns2:" for namspace "ns2". So Bar and Foo belong
to the ns2 namespace. But when I try from another namspace "ns1" to
uit test the classes. The ns2 namespace miss oe of the classes.

Please give me an explanation. And, if you can, how can I structure
the python code like C#.

Hope somebody can help


Attached are the three files: program.py, Bar.py and Foo.py.
from Bar import *
from Foo import *

class ns1:  #namespace
    def testBar():
        bar = ns2.Bar(1)
        if bar.Y == 1:
            print "Bar.Y test OK"
            print "Bar.Y test failed"
    def testFooBar():
        b = ns2.Bar.Bar(1)
        fb = ns2.FooBar(b)
        if fb.B == b.B:
            print "FooBar.B test OK"
            print "FooBar.B test failed"

    def start():

if __name__ == "program":
class ns2:  # namespace

    class Bar(object):
        def __init__(self, y=0):
            self._y = y

        # Y property
        def getY(self):
            return self._y
        def setY(self, value):
            self._y = value
        Y = property(getY,setY)
class ns2:  # namespace

    class FooBar(object):
        def __init__(self,b=None):
            self._b = b

        # B property
        def getB(self):
            return self._b
        def setB(self, value):
            self._b = value
        B = property(getB,setB)

More information about the Ironpython-users mailing list