On 10/14/2018 10:08 AM, bob gailer wrote: > ------------ Python coding "trick"1 ------------ > when I build a map I omit the () after the class e.g. 'death' = Death, > ... and apply them to the item retrieved from the map. > > use a decorator to build the map dictionary: > > # the decorator function: > def add_to_map(cls, map={}): # map is initialized to a {} when function > is "compiled" > if cls: > map[cls.__name__] = cls # add entry to dictionary > return cls > else: return map
Hint here: don't use 'map' as your own variable name, since it's a built-in function. It's not that it won't work, but is likely to cause confusion someday. Most "code inspection" systems will complain that you are shadowing or redefining a builtin (terminology may vary). The list of builtins - thus names to avoid - is here: https://docs.python.org/3/library/functions.html _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor