Nested inner classes and inheritance -> namespace problem

Larry Hastings larry at hastings.org
Wed Apr 13 23:40:57 EDT 2011


On 04/13/2011 07:37 PM, Eric Snow wrote:
> I suppose you could try something like this:
>> class Outer:
> global Inner
> class Inner:
> class Worker:
> pass
>> class InnerSubclass(Inner):
> class Worker(Inner.Worker):
> pass
>> However, that pollutes your global namespace. If you are worried 
> about that you could try: [...]

It also means that Inner is not actually /in/ Outer, and the whole point 
was to have the class accessed as Outer.Inner. But I can get what I 
wanted, if immediately after the definition of Outer I have:
 Outer.Inner = Inner
 del Inner
Thanks for the suggestion of "global Inner"! That makes this approach 
palatable.
/larry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110413/21f4fb8a/attachment-0001.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /