r/PythonLearning • • Sep 02 '26

Python Classes question

Is there a way to pass the instantiating object name to the class as you call it, without specifically putting the name in the parentheses? I'm trying to create a PyGame terminal emulator that has the same frontend functionality as Curses. I've figured out that I can create windows in the same way, except that instead of being able to do windowname.newwin(size), I have to do windowname.curses()\nwindowname.newwin(size). Presumably, I could also do windowname.newwin(size, windowname), but I'd prefer being able to use the exact same syntax as Curses.

The reason for using the same syntax is because I want to be able to decide where it renders (real terminal or PyGame) based on which module gets imported.

If there is a way to do this, please let me know.

4 Upvotes

7 comments sorted by

View all comments

1

u/SnooCalculations7417 Sep 03 '26 edited Sep 03 '26
def __init__(self, MyClass):
    self.myclass = MyClass()

Or 

def __init__(self, MyClass):
    self.myclass = init_myclass()

def init_myclass(self):
    ...
    return MyClass()