Hah, ha! Yes, that's one of the great things about carefully building a small example of a problem: you can often solve it yourself. I've avoided several posts over the years simply by trying to make a simple example program to demonstrate the problem I'm having.
...and sometimes it can cause what you've seen: You write the the program, test it, and create your post. Then shortly afterwards, you run it again and it all works.
Perhaps you forgot to save the final version of the script (that actually works) or forgot to run it and still have the error output from the previous version on your other console window. I've been there as well. 8^)
When your only tool is a hammer, all problems look like your thumb.