In doing my debugging work for 43 I was doing more complicated printing than what the video laid out. Most of it would print but some of it I could not print anything. This usually revolved around class execution…which I discovered (and probably should have realized already but didn’t until now) that when you do something like
Actually executes foo.bar(). In this example it’s relatively easy to get around if foo.bar() has been instantiated, in which case:
x = foo.bar()
Means I can do this to get what I need
But there were a couple of cases where I couldn’t figure out how to print out what I wanted without causing the code to execute itself…which obviously I didn’t want to happen since it means the code would execute twice; once in the print statement and again when that specific line was called in the code.
Take this abstract example…
class Thing(): def __init__(self, data): self.data = data def foo(self, x): pass def bar(self): return self.foo(self.data)
(in the real world foo would do something with x but in order to make this as abstract as possible I put a pass statement in there)
The question I have is how could I print out what gets returned from bar? I can’t do this…
All that would do is run the code. I don’t think it’s possible to instantiate it and print the instantiation.
Maybe there is no way to do it. But if that’s the case I need to know so I can drop this idea.