Re: Custom namespaces

2009-08-06 Thread Michele Simionato
On Aug 2, 6:46 am, Chris Rebert wrote: > > Is there any way to install a custom type as a namespace? > > For classes/objects, yes, using metaclasses. > See the __prepare__() method in PEP > 3115:http://www.python.org/dev/peps/pep-3115/ Here is an example of usage: http://www.artima.com/weblogs/

Re: Custom namespaces

2009-08-02 Thread Chris Rebert
On Sun, Aug 2, 2009 at 12:18 AM, Steven D'Aprano wrote: > On Sat, 01 Aug 2009 21:46:35 -0700, Chris Rebert wrote: > >>> Is there any way to install a custom type as a namespace? >> >> For classes/objects, yes, using metaclasses. See the __prepare__() >> method in PEP 3115: http://www.python.org/dev

Re: Custom namespaces

2009-08-02 Thread Steven D'Aprano
On Sat, 01 Aug 2009 21:46:35 -0700, Chris Rebert wrote: >> Is there any way to install a custom type as a namespace? > > For classes/objects, yes, using metaclasses. See the __prepare__() > method in PEP 3115: http://www.python.org/dev/peps/pep-3115/ Looks good, but that's Python 3 only, yes? A

Re: Custom namespaces

2009-08-01 Thread Chris Rebert
On Sat, Aug 1, 2009 at 6:06 PM, Steven D'Aprano wrote: > I was playing around with a custom mapping type, and I wanted to use it > as a namespace, so I tried to use it as my module __dict__: > import __main__ __main__.__dict__ = MyNamespace() > Traceback (most recent call last): >  File "

Re: Custom namespaces

2009-08-01 Thread Red Forks
On Sun, Aug 2, 2009 at 9:06 AM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > I was playing around with a custom mapping type, and I wanted to use it > as a namespace, so I tried to use it as my module __dict__: > > >>> import __main__ > >>> __main__.__dict__ = MyNamespace() > T

Custom namespaces

2009-08-01 Thread Steven D'Aprano
I was playing around with a custom mapping type, and I wanted to use it as a namespace, so I tried to use it as my module __dict__: >>> import __main__ >>> __main__.__dict__ = MyNamespace() Traceback (most recent call last): File "", line 1, in TypeError: readonly attribute Why is __dict__ ma