Even though global Python objects tend to be bad, I more or less forced to use them with module curses
. I currently have this:
class Window:
def __init__(self, title, h, w, y, x):
self.window = curses.newwin(h, w, y, x)
self.window.box()
self.window.hline(2, 1, curses.ACS_HLINE, w-2)
self.window.addstr(1, 2, title)
self.window.refresh()
global top_win
top_win = Window('Top window', 6, 32, 3, 6)
I am wondering whether it would be possible to get rid of the global
line by adding something to the class definition or initialisation?
class Window:
def __init__(self, title, h, w, y, x):
# Some global self magic
self.window = curses.newwin(h, w, y, x)
self.window.box()
self.window.hline(2, 1, curses.ACS_HLINE, w-2)
self.window.addstr(1, 2, title)
self.window.refresh()
top_win = Window('Top window', 6, 32, 3, 6)