Sals Shipping Unbound Local Error

Hey, I keep getting:

UnboundLocalError: local variable ‘method’ referenced before assignment

For the assignment:

I even copied the solution code in the video…

Here’s my code:

Your error message say which variable it is, and says what’s wrong (it isn’t bound when used)

If you Ctrl+F for that variable then there aren’t all that many occurrences of it that you would need to consider

Line 40

method: "premium ground"

Hey mtf,

Not sure I follow…

Can you elaborate?

Appreciate the help

Line 40 is making an attribute assignment, all the others are direct value assignments using =.

Wow, good eye. Thanks for your help

1 Like

Maybe. Because the code is short enough to make that a possibility.

But you can get there from reading the error message. It says which variable (method). It says where it happens (line number). It says what happened (variable not assigned before use) You can now look at where you think you defined it, and now you’d be looking at a single line where the problem is.

That’s what you need to be doing a lot of the time. You’ll make mistakes. Silly ones. Small ones. But if you follow up on what’s going wrong, then you can locate it without a need for a magical eye.

1 Like