Python Forum
help coding for decode filtering
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help coding for decode filtering
#4
If your function accepts input line by line, you may use function-level caching. I will show you how to use mutable default value to this end

Let's start by splitting the line unconditionally
def parse_mochad_line(self, line, _house_unit=[]):
    elements = line.split()
    classifier = ''.join(elements[2:4])
    if classifier == 'RxRFSEC':
        ......
    elif classifier == 'RxRF':
        .....
    elif classifier == 'RxPL':
        if not house_unit:
            _house_unit.append(...)
         else:
            ......
            _house_unit.clear()
Pay attention - you cannot assign _house_unit, because that will ruin caching mechanism
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
help coding for decode filtering - by dony71 - Jun-29-2018, 01:05 AM
RE: help coding for decode filtering - by scidam - Jun-29-2018, 04:18 AM
RE: help coding for decode filtering - by dony71 - Jun-29-2018, 07:19 PM
RE: help coding for decode filtering - by volcano63 - Jun-29-2018, 08:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decode string ? JohnnyCoffee 1 929 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  how to encode and decode same value absolut 2 2,505 Sep-08-2020, 09:46 AM
Last Post: TomToad
  struct.decode() and '\0' deanhystad 1 3,416 Apr-09-2020, 04:13 PM
Last Post: TomToad
  Getting decode error. shankar 8 10,704 Sep-20-2019, 10:05 AM
Last Post: tinman
  how to decode UTF-8 in python 3 oco 3 37,655 Jun-05-2018, 11:05 AM
Last Post: wavic
  Ask help for utf-8 decode/encode forfan 12 11,288 Feb-25-2017, 02:04 AM
Last Post: forfan

Forum Jump:

User Panel Messages

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