Basic inheritance question
- From: MartinRinehart@xxxxxxxxx
- Date: Sat, 5 Jan 2008 02:31:15 -0800 (PST)
Working on parser for my language, I see that all classes (Token,
Production, Statement, ...) have one thing in common. They all
maintain start and stop positions in the source text. So it seems
logical to have them all inherit from a base class that defines those,
but this doesn't work:
import tok
class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop
class token(code):
pass
x = token( tok.Loc(0, 0), tok.Loc(3, 4) )
print x.startLoc.repr(), x.stopLoc.repr()
AttributeError: token instance has no attribute 'startLoc'
1) Is my design thinking good, or hopelessly unPythonic?
2) If it's good, how do you access base class data attributes? (The
doc is rich in method access info, impoverished when it comes to other
attributes.)
.
- Follow-Ups:
- Re: Basic inheritance question
- From: Francesco Guerrieri
- Re: Basic inheritance question
- From: Paul Hankin
- Re: Basic inheritance question
- From: Jeroen Ruigrok van der Werven
- Re: Basic inheritance question
- Prev by Date: Re: cloud computing (and python)?
- Next by Date: Re: Fortran to Python
- Previous by thread: Request for loading zipped modules in some context
- Next by thread: Re: Basic inheritance question
- Index(es):
Relevant Pages
|