0

What is rv expecting for __repr__ implementations?

Using RV 4.0.12 I have been experiencing inconsistent behavior with __repr__ in python.

 

It appears that if I try to define the __repr__ as something with <>'s it doesn't respect what I've given it, if I leave them out I get inconsistent behavior where sometimes I'll get the string as given, sometimes it will prepend the classname.

 

Is there a best practices for defining repr methods in classes used in RV?

 

Here is a simple isolated test:

CODE:

class ReprTest(object):
    def __init__(self):
        pass
    def __repr__(self):
        return "<Something Useful for Debugging>"
    def __str__(self):
        return "String Representation"

class NoAngleReprTest(object):
    def __init__(self):
        pass
    def __repr__(self):
        return "Something Useful for Debugging"
    def __str__(self):
        return "String Representation"

test = ReprTest()
print "=Start Test="
print "=repr(test)="
print repr(test)
print "=test.__repr__()="
print test.__repr__()
print "=test="
print test
print "=str(test)="
print str(test)
print "=test.__str__()="
print test.__str__()

test2 = NoAngleReprTest()
print "=repr(test2)="
print repr(test2)
print "=End Test="


OUTPUT:

=Start Test=
=repr(test)=
=test.__repr__()=
=test=
String Representation
=str(test)=
String Representation
=test.__str__()=
String Representation
=repr(test2)=
Something Useful for Debugging
=End Test=

0 条评论

请先登录再写评论。