Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

copy names from a namespace and paste into another

namespace

  • Please log in to reply
1 reply to this topic

#1 kakarukeys

kakarukeys

    CC Newcomer

  • Just Joined
  • PipPip
  • 20 posts

Posted 04 June 2009 - 01:27 AM

Can this be done?
Copy all names from a namespace and paste into another and overwrite same names?
  • 0

#2 manux

manux

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 211 posts

Posted 06 July 2009 - 11:34 AM

There's an object __dict__ that is used to contain an object's objects :P
so if you have to objects a and b and want to put a.* into b without any checks, just iterate through the dictionary and copy the elements.

a = Object1()#can be anything, an instance, a module...
b = Object2()

#this will copy everything from a to b
for elem_str in a.__dict__:
   b.__dict__[elem_str] = a.__dict__[elem_str]

I don't know if it will work just like this(you need to add a few conditions so you dont overwrite things like b.__dict__ itself) but I hope you get the idea.
  • 0





Also tagged with one or more of these keywords: namespace

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download