Basic inheritance question



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.)
.



Relevant Pages

  • Re: OO refactoring trial ??
    ... As long as the concrete Python classes follow the form ... other common-to-all-taunts behavior, perhaps a common constructor, or ... in both Python and Java. ... return values derive from a common base class, ...
    (comp.lang.python)
  • Re: polymorphism problem: common signatures with no common parent
    ... > pattern or trick I'm not seeing...but given that the base class does not ... You have a class AB with no foo methods, ... // Class containing common method names. ... class ConditionalConverterInstance: public ConditionalConverter { ...
    (comp.lang.cpp)
  • Re: Downcasting - whats the problem?
    ... Root of the problem is while trying to model a problem domain we do abstractions, ... In the process we do refinement to identified classes and ... into a separate class (base class). ... When we want to invoke certain behavior on all objects that have common behavior. ...
    (comp.object)
  • Re: Basic Web Design Quesion
    ... Create a base class that all your pages inherit from, ... Use user controls, or custom server controls. ... and if your overall page design layout changes in the ... Basically what I want is to have some text/code that is common to all pages, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Forms inheritance best practice
    ... That really depends on the nature of your base class. ... > common class or implement a common interface. ... > derived form will of course be instantiated by the derived form. ...
    (microsoft.public.dotnet.framework)