Load three different modules which have the same name

abcd codecraig at gmail.com
Mon Mar 19 14:36:29 EDT 2007


I have the following directory structure setup...

c:\alpha\Person.py
------------------
class Person(IPerson):
    def __init__(self):
        print "Alpha person here"

c:\beta\Person.py
------------------
class Person(IPerson):
    def __init__(self):
        print "Beta person here"

c:\gamma\Person.py
------------------
class Person(IPerson):
    def __init__(self):
        print "Gamma person here"

c:\ok\playground.py
-------------------
def tryAllThree():
    a = "c:\\alpha"
    b = "c:\\beta"
    g = "c:\\gamma"

    sys.path.append(a)
    from Person import Person
    alpha = Person()

    sys.path.remove(a)
    sys.path.append(b)
    from Person import Person
    beta = Person()

    sys.path.remove(b)
    sys.path.append(g)
    from Person import Person
    gamma = Person()

Notice that my three different projects (alpha, beta, gamma) have a
Person.py which contains a Person class.

When I execute the following (on windows):

c:\ok> python
>>> from playground import *
>>> tryAllThree()

I see...
Alpha person here
Alpha person here
Alpha person here

What I want to see is
Alpha person here
Beta person here
Gamma person here

....how can I get this to work?

Thanks




More information about the Python-list mailing list