It's me wrote:
This must be another newbie gotchas.

Consider the following silly code
[snip tightly coupled code]

A few options that also might work better than such tightly coupled modules:

-------------------- file1.py --------------------
import file2
myBaseClass = file2.BaseClass()
class NextClass:
    def __init__(self):
        for eachChild in myBaseClass.MyChilds:
            pass
myBaseClass.AddChild(file2.NextClass())
--------------------------------------------------

-------------------- file2.py --------------------
class BaseClass:
    def __init__(self):
        self.MyChilds = []
    def AddChild(self, NewChild):
        self.MyChilds.append(NewChild)
--------------------------------------------------


or


-------------------- file1.py -------------------- import file2 myBaseClass = file2.BaseClass() myBaseClass.AddChild(file2.NextClass(myBaseClass)) --------------------------------------------------

-------------------- file2.py --------------------
class BaseClass:
    def __init__(self):
        self.MyChilds = []
    def AddChild(self, NewChild):
        self.MyChilds.append(NewChild)
class NextClass:
    def __init__(self, myBaseClass):
        for eachChild in myBaseClass.MyChilds:
            pass
--------------------------------------------------
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to