79263427

Date: 2024-12-08 22:06:38
Score: 5
Natty:
Report link

Based on what @Grismar said, it sounds like the answer is that the locals() built-in function only shows things defined in the local scope. In other words, if we define Python scoping as LEGB, locals() only displays the "L" part. For what I was trying to do, I need to use the globals() built-in.

As for VS Code, it appears that when using the Python debugger in VS Code that locals() displays more than just the "L" scope. However, I believe pdb is the definitive debugger and that only shows things in the "L" scope.

Finally - is what I'm trying to do a good idea? Maybe/maybe not. In a nutshell - I'm doing Cloud hosted code challenges. The cloud environment defines their own variables (globals) that make sense for them (a Linux hosted environment). I choose to solve the challenges locally on a Windows environment. My environment is quite a bit different, so I define my own variables that make sense for my environment. I want to do something generic that works in either environment, so I check if my variable is defined. If yes use it, if no fallback to the cloud definition. There's probably a better way to do this and I'm open to suggestions.

Thanks for all the feedback.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • No code block (0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @Grismar
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: James S.