#1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    43
    Rep Power
    0

    get unique elements


    my code gets data from a richedit control in another application, in the form of a list (each element is 1 line). The trouble is, it is sometimes updated more than once per second, and when it's updated, new lines are added, the original stuff stays in there.

    I need to get it line by line, but every time i get the contents obviously i get a huge list containing all the original stuff, plus the extra few lines.

    Is there anyway that i can compare the original copy and a new copy, and add the new lines to the original?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I believe the easiest way to solve this kind of problem is by using Pythons set() type. However if you did want to do it another way you could use the difflib or maybe filecmp; this last module will only be really useful with data stored in a file but I thought it worth mentioning as an option .

    http://python.org/doc/2.4.1/tut/node7.html#SECTION007400000000000000000

    http://python.org/doc/2.4.1/lib/module-difflib.html
    http://python.org/doc/2.4.1/lib/module-filecmp.html

    I hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Originally Posted by miagigaim
    my code gets data from a richedit control in another application, in the form of a list (each element is 1 line). The trouble is, it is sometimes updated more than once per second, and when it's updated, new lines are added, the original stuff stays in there.

    I need to get it line by line, but every time i get the contents obviously i get a huge list containing all the original stuff, plus the extra few lines.

    Is there anyway that i can compare the original copy and a new copy, and add the new lines to the original?
    It might help to tell us what widget set the richedit control is written in and how the two programs are communicating.

    Do you have access to the richedit control code to make changes?

    grim
  6. #4
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    43
    Rep Power
    0
    Originally Posted by Grim Archon
    It might help to tell us what widget set the richedit control is written in and how the two programs are communicating.

    Do you have access to the richedit control code to make changes?

    grim
    it's another program entirely, i am using win32 functions to get handles to it's controls like it's richedit box.

    i wonder if there is any quick win32 way to do this??

    i am using the same functions to press the write buttons depending on what's in the text box. i created something like this last night:

    Code:
    hwnd = '102893' # handle to window
    linelist = []
    while len(linelist) < 30 :
       tmp = getLines(hwnd) # get lines gets ALL lines into list
       for i in tmp :
          if i not in linelist :
             linelist.append(i)
       time.sleep(2)
    
    print linelist

    I had to do the pause at the end cus otherwise it would just hang. I then copied/pasted from the edit control and compared both. Largely they were the same but there were some variations, which is where i am concerned.

IMN logo majestic logo threadwatch logo seochat tools logo