Python complaints
Robert Roy
rjroy at takingcontrol.com
Thu Dec 2 16:02:20 EST 1999
On 24 Nov 1999 10:38:27 +0000, Gareth McCaughan
<Gareth.McCaughan at pobox.com> wrote:
...
> - Method definitions have to be lexically contained in
> class definitions. So suppose you write something that
> parses a language and then does various things with
> the parse tree; if you adopt an OO approach to the
> parse tree (with things like "class IfStatement(ParseNode):")
> then you can't separate out very different operations like
> foo.print(), foo.compile() and foo.evaluate(). (That is,
> you can't group all the print methods together, and group
> all the compile methods together somewhere else, etc.)
> You can, of course, split your code up by having the WhileLoop
> and UntilLoop classes in different files, but this seems
> less sensible to me. :-) (This particular gripe applies to
> most OO languages.)
>
Unless I misunderstood your post, the following code would do the job
nicely.
bar.py
def bar(self):
print self.__class__.__name__
def bar2(self):
print 'In bar 2',
self.bar
foo.py
class foo:
from bar import *
if __name__ == '__main__':
f = foo()
f.bar()
f.bar2()
foo2.py
class foo2:
from bar import *
if __name__ == '__main__':
f = foo2()
f.bar()
f.bar2()
of course this is just a slightly more akward way of writing
bar.by
class bar:
def bar(self):
print self.__class__.__name__
def bar2(self):
print 'In bar 2',
self.bar
foo.py
from bar import bar
class foo(bar):
pass
....
>--
>Gareth McCaughan Gareth.McCaughan at pobox.com
>sig under construction
More information about the Python-list
mailing list