Announcement

Collapse
No announcement yet.

finding index of a certain snap address in a string of addresses

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • finding index of a certain snap address in a string of addresses

    ----------edit---------
    For the life of me I can't get code to stay with proper indentation ....... I'll attach a screen shot to make it easier to read
    ----------end edit-------


    I have a global string that contains all the addresses of chips in the network.

    I have another global string that contains 8 16 bit integers (actuator states) for each address in the address global string

    If I know the index of the matching address I know which set of 8 to update

    Since snap does not have the find function I decided to make my own.

    what I want is to send two parameters (list of all addresses, address to find) with a return of the index of the first hex of the matching address

    def getAddIndex(allAdd, toFind):

    index = 9 # 9 used to tell no match was made as 0 is a possible answer
    numAdd = (int(len(allAdd)) / 3) #unknown number of addresses so this gives me the number of addresses in the string
    for i in xrange(numAdd):
    offset = (i * 3)
    if allAdd[offset] == toFind[0] and allAdd[offset + 1] == toFind[1] and allAdd[offset + 2] == toFind[2]:
    index == offset

    return index


    This function will only return 9 when I know there is a match and for the life of me I can't figure out why. The addresses are in hex form used in rpc

    Any help would be appreciated
    Attached Files
    Last edited by mtalent; 11-21-2017, 06:49 PM.

  • #2
    index == offset is a comparison, not an assignment...

    You could do the search a bit more efficiently as: if allAdd[offset : offset+3] == toFind:
    Last edited by jasonharper; 11-22-2017, 03:35 PM. Reason: de-emojied

    Comment


    • #3
      First off your good, it could have taken days to notice that. (I do know the difference).

      second yes you are correct just slice the entire address makes perfect sense and is much easier to do.

      I don't know sometimes my built in logic system (brain) just stops feeding me what I need.

      Thanks Jason it is very helpful to have another set of eyes.

      I owe you a beer someday

      Mark

      Comment

      Working...
      X