Closed Thread
Results 1 to 2 of 2

Thread: copy names from a namespace and paste into another

  1. #1
    kakarukeys is offline Newbie
    Join Date
    Apr 2009
    Posts
    20
    Rep Power
    0

    copy names from a namespace and paste into another

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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    manux's Avatar
    manux is offline Programming Professional
    Join Date
    Oct 2008
    Posts
    234
    Blog Entries
    1
    Rep Power
    14

    Re: copy names from a namespace and paste into another

    There's an object __dict__ that is used to contain an object's objects
    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.

    Code:
    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cut/copy/Paste in forms
    By kemnet in forum C# Programming
    Replies: 19
    Last Post: 08-11-2011, 07:13 AM
  2. The copy & paste coding generation
    By PsychoCoder in forum Technology Ramble
    Replies: 11
    Last Post: 06-01-2011, 01:51 AM
  3. Copy paste from a listview
    By williamevanl in forum C# Programming
    Replies: 0
    Last Post: 01-05-2011, 10:42 AM
  4. C# copy and paste web content
    By Siten0308 in forum C# Programming
    Replies: 1
    Last Post: 04-18-2010, 07:43 PM
  5. Copy paste program
    By Drmarcus in forum General Programming
    Replies: 2
    Last Post: 09-01-2009, 06:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts