[Tutor] Already Initialized Object Inheritance?

WolfRage wolfrage8765 at gmail.com
Thu Jun 16 04:20:32 CEST 2011


Christopher,

Thank you for the explanation of the error. I see now why I am unable to
reference it outside of __init__'s scope. No, I did not mean to do that.
I will include further details in my reply to Steven. Please feel free
to jump in on that conversation to continue my learning. Thank you for
your help and time thus far. 
--
Jordan

On Wed, 2011-06-15 at 09:45 -0400, Christopher King wrote:
> Oh, I think I see the error.
> self=stdscr
> This will just make the variable called self be assigned to
> stdscr with in __init__ This will not make the object actually turn
> into stdscr
> Or maybe you meant do that, because I don't know what stdscr or
> the curses module is
> 
> 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