On Mon, 20 Aug 2018 22:55:26 +0300, Marko Rauhamaa wrote:

> Dan Sommers <d...@tombstonezero.net>:
> 
>> On Mon, 20 Aug 2018 14:39:38 +0000, Steven D'Aprano wrote:
>>> I have often wished Python had proper namespaces, so I didn't have to
>>> abuse classes as containers in this way :-(
>>> 
>>> (Not that I do this using "inner classes", but I do often want to use
>>> a class as a container for functions, without caring about "self" or
>>> wrapping everything in staticmethod.)
>>
>> Isn't that what modules are for?  (I suspect that I'm missing
>> something, because I also suspect that you knew/know that.)
> 
> What's the syntax for creating an inner module...?

from types import ModuleType
m = ModuleType('m')
m.one = 1
m.a = 'a'
m.b = lambda x: x + one


except that not only doesn't it look nice, but it doesn't work because 
the m.b function doesn't pick up the m.one variable, but a global 
variable instead.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to