In the first case, you fetch the class object of importme.MyClass
, and the string you print is its repr
, i.e. the repr
of the class object.
In the second case, you create an instance of type MyClass
, in which case, printing invokes your custom repr
(__repr__
applies to the instance of the class).
By the way, since you first import importme
, this
getattr(sys.modules['importme'], sys.argv[1])
is equivalent to this:
getattr(importme, sys.argv[1])
I'm guessing what you meant to do in the first case is this:
m = getattr(importme, sys.argv[1])()