0

I have a curses program that I want to invoke from Python shell by just typing hh.

So, I have tried this:

class hh:
    def __str__(self):
        curses.wrapper(main)
    def __repr__(self):
        curses.wrapper(main)

...and then in shell:

>>> from package.module import hh
>>> hh
<class 'package.module.hh'>

However, had no success as you can see.

How can I invoke my curses program from Python shell by just typing hh? That is, is it possible to call a function without the method invocation operator, i.e., with no parentheses? Or what else could I do that would have had the same effect?

adder
  • 3,512
  • 1
  • 16
  • 28
  • You can call a `staticmethod` without instantiating the object first – NomadMonad Apr 22 '20 at 13:23
  • 1
    `hh` is just a *class*, you don't even have an instance for the methods you *have* defined to be called on. If you want to implement the repr method on the *class*, you need to look into *metaclasses*. Not returning a string is a `TypeError`, though. – jonrsharpe Apr 22 '20 at 13:23
  • Those are some pretty strange (bordeing on abuse) overloads, but they also apply to instances of `hh`, not to the class. – molbdnilo Apr 22 '20 at 13:24

0 Answers0