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. Advertisements

  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. Advertisements

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. ravi sankar
    Replies:
    2
    Views:
    527
    abdul bari
    Aug 27, 2003
  2. D. Shane Fowlkes
    Replies:
    1
    Views:
    1,130
    Tu-Thach
    Jan 13, 2004
  3. Tobiah
    Replies:
    2
    Views:
    416
    Tobiah
    Sep 14, 2003
  4. Harlin Seritt
    Replies:
    10
    Views:
    606
    Harlin Seritt
    Mar 5, 2005
  5. Francisco Borges

    importing two modules with the same name

    Francisco Borges, Mar 19, 2005, in forum: Python
    Replies:
    5
    Views:
    463
    Francisco Borges
    Mar 20, 2005
  6. Replies:
    4
    Views:
    668
    Joe Kesselman
    Feb 25, 2007
  7. Fabrizio Pollastri

    merging the global namespaces of two modules

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

    Importing v reloading modules modules

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