Persevere Through Obstacles
00:00 So far, we have looked at the code itself, our first impression, and the first impression of the question, which started with a how, so we try to focus more on improvements that we can do on the code itself to make it work.
00:26 We mentioned already before that Pylance tells us that there’re, like, an undefined variable. You might expect that there’s going to be an error here. So if I run the original file, there’s currently nothing happening, which is just because in the code snippet that we got here, there’s no function call.
you see that Pylance in line 29 already tells us again that, well, there’s actually two things that’s missing—a parameter
main() function needs something, and I think that’s very good that you’re kind of, like, you’re just hitting an obstacle. You’ve got this code, you want to help, and then you’re like, “Oh wait, actually I have to put something in.” So now you have to try to understand what this
X is that the
main() function has there. Good point.
So my thought process was I’m going to run this and I know I’m going to run into an error because of line 25, but I don’t even get to that. Like I’m going to run into another error before, which is that
main() is missing one required positional argument,
01:32 And that’s just like Philipp said, I’m just confronted with a bunch of obstacles to actually get to the point of helping this person with a question. Let’s go ahead and try to make this a working example.
And so I need to figure out what is
X, right? So I need to look into this code and see where is it used. And in that case it looks like it’s a dictionary structure where the person is performing some look-up on two keys,
"t", which means that I’m going to here have to have a dictionary that has, let’s say,
"s" and that points to something. I have no idea what it points to.
Like, I don’t know what
X is. I’m just trying to figure out from the code what is the data structure I need to actually get this to run. Okay, now I’m passing this in as
X and then I can try running it again.
returns, so— Yeah, that’s going into the more details of the code. So one thing that happens here in line 22 is you’re starting with a
try statement, and you are catching the exception in line 26, like any exception basically.
What we can see here is also, like, that if you use this very general exception, you catch all of the exceptions. So what we ran into now is that this person’s probably trying to catch some of these exceptions that are happening inside of
load_model(), but it’s also catching the exception that’s raised here, that you have, like, an undefined variable. So we don’t even come to this error, but it’s still a problem in the code basically that makes it not run the way that we would want to.
Become a Member to join the conversation.