Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
same context functions
#11
you mean a dictionary to get a function reference which i pass the instance variable to? why not a list? are lists not directly indexed?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
Skaperen Wrote:why not a list?
Because you want to choose the logic according to arriving code value
    logic = {
        'a': self.a_logic,
        'b': self.b_logic,
        ...
    }
    ...
    for c in line:
        logic.get(c, default)() # <-- This replaces the sequence of elifs
Reply
#13
which a list can do ... at least in the case of what i was doing which was processing ASCII control codes. so it would be a check for value below 32 and a 32-list or 32-tuple.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  exception context Skaperen 0 2,305 Mar-06-2021, 08:42 PM
Last Post: Skaperen
  function to store in caller's context Skaperen 7 2,957 Jul-27-2020, 08:45 PM
Last Post: Skaperen
  turning my function into a context manager Skaperen 2 1,927 Nov-14-2019, 09:08 PM
Last Post: Skaperen
  i want to make my own context manager Skaperen 0 1,643 Nov-10-2019, 05:21 AM
Last Post: Skaperen
  Windows Context Menu Depth GWild 0 2,303 Jan-27-2018, 07:18 AM
Last Post: GWild

Forum Jump:

User Panel Messages

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