Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python: for and if loop
#1
I made this function to code some values according to func_code value but it does not work as aaspected:

  def reg_val_list_binary2(s):
    r = []
    for i in func_code(s):
        try: 
            if  i == 3:
                r = reg_val_list3(s)
            elif  i == 1: 
                r = reg_val_list_binary(s)
        except AttributeError:
            pass
    return r
Finction reg_val_list3(s) is coded as follows:

   def reg_val_list3(s):
    v = []
    for p in s:
        if p.haslayer('ModbusADUResponse'):
            try:
                if p['ModbusADUResponse'][1].funcCode == 3:
                    v += p['ModbusADUResponse'][1].registerVal
            except AttributeError:
                pass
    return v
And function reg_val_list_binary(s):

   def reg_val_list_binary(s):
    r = []
    for x in reg_val_list1(s):
        r += [int(bit)for bit in str( bin(x) )[2:].zfill(8)] [::-1]
    return r
The problem is I have the impression that it cannot find func_code == 1 while it's in the func_code(s) list

Any idea?
Reply


Messages In This Thread
Python: for and if loop - by salwa17 - Jun-19-2020, 12:40 PM
RE: Python: for and if loop - by deanhystad - Jun-19-2020, 01:07 PM
RE: Python: for and if loop - by Yoriz - Jun-19-2020, 02:32 PM
RE: Python: for and if loop - by salwa17 - Jun-20-2020, 03:15 PM
RE: Python: for and if loop - by deanhystad - Jun-22-2020, 01:17 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020