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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top