0

Can we change the output of class string? note: I am talking about class not instance

for example:

class Foo(object):
    baz=10
    def __init__(self,value):
        self.value=value

    def bar(self):
        self.a="3llo world"

    def __str__(self):
        return "not me"

    def __repr__(self):
        return "not me either"

print Foo

output:

<class '__main__.Foo'>

where does the output come from? thanks

jamylak
  • 128,818
  • 30
  • 231
  • 230
cppython
  • 1,209
  • 3
  • 20
  • 30
  • In the duplicate you'll see the answer is to simply definie `__str__` on the metaclass – jamylak Dec 15 '14 at 08:43
  • I think that because the class you declared is `Foo` and when you type `print Foo`, it will return a kind of `class` object. About the class string, I think that you can't because class is something abstract and you cannot call a class to do something. Check my thought if I am wrong! – Phuc Tran Dec 15 '14 at 08:44
  • @PhucTran That is what OP wants, just to change the text in that case – jamylak Dec 15 '14 at 08:45
  • @PhucTran You are wrong, click on the duplicate and you can see its possible – jamylak Dec 15 '14 at 08:49
  • please close as duplication. thank you for jamylak – cppython Dec 15 '14 at 08:50

0 Answers0