Python Forum
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
#36
(Aug-10-2018, 05:44 PM)PySimpleGUI Wrote: Check out this bit of Python magic!
class ListDict(OrderedDict):
    def __iter__(self):
        for v in self.values():
            yield v
            
    def __getitem__(self, item):
        if isinstance(item, slice):
            return list(self.values())[item]
        else:
            return super().__getitem__(item)
This way there is no need to call value.values. I can access the return values in both dictionary style and as a list! I think it's kinda brilliant. I can't take credit for it however :-) But I can freely use it!

Why bring complexity into this situation when you have a simple soultion? The ListDict may be a cute design but is verbose here and creates extra obstacle to the user.
Reply


Messages In This Thread
RE: [PySimpleGUI] Tutorial - Name, Address, Phone GUI - by jfong - Aug-11-2018, 02:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PySimpleGUI Try Except jamesaarr 1 2,058 Nov-18-2021, 02:02 PM
Last Post: jamesaarr

Forum Jump:

User Panel Messages

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