[Tutor] Already Initialized Object Inheritance?

WolfRage wolfrage8765 at gmail.com
Wed Jun 15 08:42:59 CEST 2011


Unfortunately I am not able to inherit "stdscr" using that method. As
Python returns with an error stating that "stdscr" is not defined. This
error is returned at run time and by the compiler prior to actual
execution. If you would like I can write a quick example that will
generate the error message for that method.
--
Jordan
On Wed, 2011-06-15 at 02:04 -0400, Japhy Bartlett wrote:
> When you're subclassing something, you use the syntax:
> 
> class Foo(Bar):
> 
> It seems like you're trying to do:
> 
> class Bar:
>     class Foo:
> 
> - Japhy
> 
> On Wed, Jun 15, 2011 at 12:47 AM, WolfRage <wolfrage8765 at gmail.com> wrote:
> > I can not get this to behave in the manor that I would like. I am trying
> > to have an object refereed to as CursesApp.Screen become the already
> > initialized object "stdscr". To elaborate I would like it to become that
> > object but to also be able to define additional methods and properties,
> > so more along the lines of inherit from "stdscr". Is this even possible?
> > Well I can make it equal to that object I can not add additional methods
> > and properties to it? Additionally, so that I learn; where has my
> > thinking been too short sited? Thank you for your help.
> > --
> > Jordan
> >
> > ****CODE BELOW****
> >
> > #!/usr/bin/python3
> > """With thi method I can make the class "Screen" become "stdscr" but if
> > I refernce any of the new methods or properties the applications
> > promptly fails and notifies me that the method or property does not
> > exist. Another downside of this method is I can not reference
> > self.Screen.* or it crashes."""
> > import curses
> > class CursesApp:
> >    def __init__(self, stdscr):
> >        self.Screen(stdscr) #This is the stdscr object.
> >        curses.init_pair(1,curses.COLOR_BLUE,curses.COLOR_YELLOW)
> >        #self.Screen.bkgd(' ', curses.color_pair(1))
> >        #self.mainLoop()
> >
> >    #def mainLoop(self):
> >        #while 1:
> >            #self.Screen.refresh()
> >            #key=self.Screen.getch()
> >            #if key==ord('q'): break
> >
> >    class Screen:
> >        def __init__(self,stdscr):
> >            self=stdscr
> >            #self.height, self.width = self.getmaxyx() # any reference
> > to these crashes
> >            #self.offsety, self.offsetx = -self.height/2, -self.width/2
> > # any reference to these crashes
> >            #self.curx, self.cury = 1, 1 # any reference to these
> > crashes
> >            self.clear()
> >            self.border(0)
> >            while 1:
> >                self.refresh()
> >                key=self.getch()
> >                if key==ord('q'): break
> >
> > def main():
> >    cursesapp = curses.wrapper(setup)
> >
> > def setup(stdscr):
> >    CursesApp(stdscr)
> >
> > if __name__ == '__main__':
> >    main()
> >
> >
> >
> > ****CODE BELOW****
> >
> > #!/usr/bin/python3
> > """With this method I can make "Screen" become "stdscr" but if I
> > obviously can not even define any new methods or properties. But atleast
> > the references can be used through out the class with out crashing."""
> > import curses
> > class CursesApp:
> >    def __init__(self, stdscr):
> >        self.Screen=stdscr #This is the stdscr object.
> >        curses.init_pair(1,curses.COLOR_BLUE,curses.COLOR_YELLOW)
> >        self.Screen.bkgd(' ', curses.color_pair(1))
> >        self.mainLoop()
> >
> >    def mainLoop(self):
> >        while 1:
> >            self.Screen.refresh()
> >            key=self.Screen.getch()
> >            if key==ord('q'): break
> >
> > def main():
> >    cursesapp = curses.wrapper(setup)
> >
> > def setup(stdscr):
> >    CursesApp(stdscr)
> >
> > if __name__ == '__main__':
> >    main()
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >




More information about the Tutor mailing list