Python complaints
skaller
skaller at maxtal.com.au
Fri Dec 3 16:04:44 EST 1999
Gareth McCaughan wrote:
>
> Robert Roy wrote:
>
> [I said:]
> >> - 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 *
> [etc]
>
> That allows me to split up a class's methods into several
> different files, true. On the other hand, they can't then
> be grouped in some other way.
Yes, they can. It is a common technique,
to make various tables of functions. You can build objects
like class foo in python using 'exec', if necessary.
This requires more than 'from bar import *', but using
that doesn't _exclude_ other groupings.
--
John Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850
More information about the Python-list
mailing list