In the following, why it is not printing results even though I don't see any errors:
class Test(object):
def __init__(self, x, y):
self.x = x
self.y = y
def printing(self):
var = self.x + self.y
print(" RESULT= %i " % var)
if __name__ == '__main__':
Test().printing(10, 20)
asked Mar 30, 2016 at 19:00
Jack Hoff.
1431 gold badge3 silver badges7 bronze badges
-
1Your first order of business is to figure out why you're not seeing any errors; that code should definitely generate one.DSM– DSM2016年03月30日 19:02:41 +00:00Commented Mar 30, 2016 at 19:02
-
Yes I just noticed my mistake. I just don't know why I could not spot it. I apologizeJack Hoff.– Jack Hoff.2016年03月30日 19:05:33 +00:00Commented Mar 30, 2016 at 19:05
-
Wait, when you said "I don't see any errors", did you mean "I think my code is right even though there is an error", or do you mean "it generated no errors"? I thought you meant the second and that something was wrong with your Python setup. If you see that your code is generating an exception, you should always copy and paste it into your questionsDSM– DSM2016年03月30日 19:16:55 +00:00Commented Mar 30, 2016 at 19:16
-
I meant it generated no errors.Jack Hoff.– Jack Hoff.2016年03月30日 21:31:10 +00:00Commented Mar 30, 2016 at 21:31
1 Answer 1
if __name__ == '__main__':
Test().printing(10, 20)
Should be
Test(10, 20).printing()
You have mistake in instance initialization.
answered Mar 30, 2016 at 19:01
xiº
4,7173 gold badges31 silver badges43 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py