combining namespaces when importing two modules

Discussion in 'Python' started by Donnal Walter, Aug 22, 2005.

  1. 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
    Donnal Walter, Aug 22, 2005
    #1
    1. Advertising

  2. Donnal Walter

    Peter Hansen Guest

    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
    Peter Hansen, Aug 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tobiah
    Replies:
    2
    Views:
    310
    Tobiah
    Sep 14, 2003
  2. Francisco Borges

    importing two modules with the same name

    Francisco Borges, Mar 19, 2005, in forum: Python
    Replies:
    5
    Views:
    320
    Francisco Borges
    Mar 20, 2005
  3. Replies:
    4
    Views:
    495
    Joe Kesselman
    Feb 25, 2007
  4. Fabrizio Pollastri

    merging the global namespaces of two modules

    Fabrizio Pollastri, May 22, 2008, in forum: Python
    Replies:
    4
    Views:
    295
    Diez B. Roggisch
    May 22, 2008
  5. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    296
    Peter Peyman Puk
    Mar 19, 2010
Loading...

Share This Page