combining namespaces when importing two modules

D

Donnal Walter

I would like to be able to write something like:

import dcw as dw
import xyz as dw

such that the 'dw' namespace includes definitions from both dcw and xyz,
but in the script above names from dcw1 are lost. How can I combine the
two? (I'd rather not use 'import *'.) Thanks.

Best regards,
Donnal Walter
Arkansas Children's Hospital
 
P

Peter Hansen

Donnal said:
I would like to be able to write something like:

import dcw as dw
import xyz as dw

such that the 'dw' namespace includes definitions from both dcw and xyz,
but in the script above names from dcw1 are lost. How can I combine the
two? (I'd rather not use 'import *'.) Thanks.

This sounds really gross and dangerous, but you could do this, and it
might even work. I wouldn't recommend it, but without knowing your use
case I can't say what I'd recommend instead.

import dcw as dw
import xyz as _
dw.__dict__.update(_.__dict__)
del _


-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top