Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > combining namespaces when importing two modules

Reply
Thread Tools

combining namespaces when importing two modules

 
 
Donnal Walter
Guest
Posts: n/a
 
      08-22-2005
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


 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      08-22-2005
Donnal Walter wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing v reloading modules modules Peter Peyman Puk Python 0 03-19-2010 05:09 PM
merging the global namespaces of two modules Fabrizio Pollastri Python 4 05-22-2008 01:16 PM
combining names and namespaces into a one URI nallen05@gmail.com XML 4 02-25-2007 07:58 PM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM



Advertisments