If yes, can you suggest a better way than below? Please elaborate/justify.
class X:
...
if __name__ == '__main__':
# TODO: Should we bother doing this?
errorMessage = 'This class is not meant to have a main method. Do not execute directly.'
print(errorMessage)
raise Error(errorMessage)
I would not do this.
Here's why: python -i scriptname.py
can be used to load in the script and drop to the interactive console post running of the script. So what you then get is all the defined functions, which you can then manipulate / test as you see fit.
Your way, you'd get an error doing this.