Newbie namespace question

Jeff Shannon jeff at ccvcorp.com
Wed Dec 22 14:02:27 EST 2004


bcarlso at gmail.com wrote:

>Now, in jdbc.py I have
>
>#jdbc.py
>class DataSource:
>def __init__(self, servername):
>self.servername = servername
>
>def create(name, connectionInfo, etc):
>#Call the IBM supplied WebSphere config object
>AdminConfig.create('DataSource')
>
>Run it and get a name error, which, makes sense.
>If I try to use the standard import solution as deelan suggests I have
>a circular reference on the imports and I get an error that it can't
>import class DataSource (presumbably because it hasn't gotten far
>enough through jdbc.py to realize that there's a DataSource class
>defined.
>  
>

How about you try this?

def create(name, connectionInfo, ...):
    from configure_server_foo import AdminConfig
    AdminConfig.create('DataSource')

This way, jdbc.py won't try to import configure_server.foo until 
create() is called.  By deferring that import, you should be able to 
avoid the circular import problem...

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list