inner classes in python as inner classes in Java

Gonçalo Rodrigues op73418 at mail.telepac.pt
Thu Oct 16 10:26:43 EDT 2003


On Thu, 16 Oct 2003 09:48:52 +0200, "Carlo v. Dango" <oest at soetu.eu>
wrote:

[text snipped]

>
>aaaah come on :) you really cannot see the nice things of having a scope 
>for inner class instances?? It's like inner method.. atleast they share 
>scope with their outer method... if it didn't it would render inner 
>methods almost useless..
>
>class A(object):
>	def foo(self):
>		i = 3
>		def bar():
>			print i
>
>		bar()

What do you *really* want? As far as I remember (it's been a long time
since I've dealt with Java), the biggest use for inner classes in Java
is in faking closures. That's a non-issue in Python, in part because
*every* object is a first class citizen, functions, methods and
classes included. There is no such thing as a class-scope, only
function definitions open a new (local) scope. As others have posted
you *can* fake that with __setattr__ and/or a metaclass solution, but
*why* would you want to go down that path that is what I cannot
fathom.

With my best regards,
G. Rodrigues




More information about the Python-list mailing list