On Friday, July 1, 2016 at 8:19:36 PM UTC+5:30, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > > > Sometimes we have a group of related functions and variables that belong > > together, but are not sufficiently unrelated to the rest of the module that > > we want to split them out into another file. > > > Here's a proof of concept. I use a class with a custom metaclass like this: > > > > > > # Python 3 version > > class ExampleNS(metaclass=Namespace): > > x = 1 > > y = [] > > > > def spam(n): > > return 'spam'*n > > > py> Example.spam(5) > > 'spamspamspamspamspam' > > > Why not just extend the capabilities of a class? I actually thought this > would work until I tried it and it didn't:
Well I also thought similarly -- sure a normal (instance) method cannot be used without an instance but sure this is what class/static methods are for? ie Steven's option 4. Then I remembered that python's LEGB rule is bizarre: Outer scopes are added outside inner scopes ... except for classes -- https://mail.python.org/mailman/listinfo/python-list