List Info

Thread: Intra-package import




Intra-package import
country flaguser name
Australia
2007-07-25 07:22:48
Hi all,

I have a problem with intra-package import. Assuming this is
my 
directory structure:

dws/
       __init__.py
      
       common/
             threadpool.py

       dal/
             d_connect.py

How can I, in d_connect.py, import a class from
../common/threadpool.py, 
say ThreadPool.py?
Basically I am trying to do a C equivalent of #include 
"../include/my_header.h".

Any ideas?

Thanks in advance.

Cheers
Maurice
_______________________________________________
melbourne-pug mailing list
melbourne-pugpython.org
http://mail.python.org/mailman/listinfo/melbourne-pug

Re: Intra-package import
country flaguser name
Australia
2007-07-25 07:27:45
If dws is in the python path, you can do "from
dws.common.threadpool  
import ThreadPool".  If dws is not in sys.path, perhaps
you should  
put it there? 

(At least in pre-2.4, I'm not aware of a nice answer for
this except  
for to put your package into site-packages or add it to
sys.path via  
another method.  Other people may have better ideas for
you.)

KevinL

On 25/07/2007, at 10:22 PM, Maurice Ling wrote:

> Hi all,
>
> I have a problem with intra-package import. Assuming
this is my
> directory structure:
>
> dws/
>        __init__.py
>
>        common/
>              threadpool.py
>
>        dal/
>              d_connect.py
>
> How can I, in d_connect.py, import a class from
../common/ 
> threadpool.py,
> say ThreadPool.py?
> Basically I am trying to do a C equivalent of #include
> "../include/my_header.h".
>
> Any ideas?
>
> Thanks in advance.
>
> Cheers
> Maurice
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pugpython.org
> http://mail.python.org/mailman/listinfo/melbourne-pug

KevinL
---
Obsidian Consulting Group
web: http://www.obsidian.com.a
u/
phone: +613 9355 7844 (ext 2001)
fax: +613 9350 4097


_______________________________________________
melbourne-pug mailing list
melbourne-pugpython.org
http://mail.python.org/mailman/listinfo/melbourne-pug

Re: Intra-package import
user name
2007-07-25 17:15:21
What Kevin said is the best answer.
I can't think of a reason not to have your top level package
in your path.

Otherwise look at imp.find_module and imp.load_module
_______________________________________________
melbourne-pug mailing list
melbourne-pugpython.org
http://mail.python.org/mailman/listinfo/melbourne-pug

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )