Python Forum
simplifying a stack of elifs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simplifying a stack of elifs
#1
i have a thread function with a role of handling some commands it gets from a queue. there a lot of statement groups like:
    elif msg[0] == 'some command name':
        ...
        # statements to handle that command
        ...
i was thinking of having a mapping of function references but every command involves accessing and modifying local variables, so the functions aspect of this just makes things worse with all the detail to exchange data with the caller (passing locals() is not an option because modifications can't be done that way). if there was a way to run a function in the same context as the caller, that would be a nice direct solution. even calling exec() with the code in a string because passing locals() is still a dictionary that can't be modified.

any ideas?
Tradition is peer pressure from dead people

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


Messages In This Thread
simplifying a stack of elifs - by Skaperen - Aug-14-2019, 04:23 AM
RE: simplifying a stack of elifs - by Gribouillis - Aug-14-2019, 07:05 AM
RE: simplifying a stack of elifs - by Skaperen - Aug-14-2019, 06:13 PM
RE: simplifying a stack of elifs - by Gribouillis - Aug-15-2019, 06:15 AM
RE: simplifying a stack of elifs - by Skaperen - Aug-15-2019, 08:22 PM
RE: simplifying a stack of elifs - by Gribouillis - Aug-15-2019, 09:16 PM
RE: simplifying a stack of elifs - by Skaperen - Aug-15-2019, 11:51 PM
RE: simplifying a stack of elifs - by Gribouillis - Aug-16-2019, 06:51 AM
RE: simplifying a stack of elifs - by Skaperen - Aug-17-2019, 04:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help for simplifying code mmk1995 8 4,329 Sep-24-2019, 02:04 PM
Last Post: perfringo
  a stack of elifs and a try/except Skaperen 2 2,048 Sep-12-2019, 11:39 PM
Last Post: Skaperen
  Simplifying my code ilondire05 5 3,879 Jul-21-2019, 03:21 AM
Last Post: scidam
  My program subtracts fractions, but for some reason isn't simplifying them RedSkeleton007 9 6,076 Mar-03-2018, 11:45 AM
Last Post: Gribouillis
  Simplifying multiple "or" conditions in if statement. rhubarbpieguy 8 102,530 Jul-22-2017, 12:19 PM
Last Post: rhubarbpieguy

Forum Jump:

User Panel Messages

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