In C/C++, a function can declare a local variable as static. When doing so, the value remains in memory and is available to subsequent calls to the function (this variable is no longer local, but that’s besides the point). Is there a way to do something similar in Python, without having to declare any global variable outside of the function?
Tag: local-variables
Using locals() and format() method for strings: are there any caveats?
Are there any disadvantages, caveats or bad practice warnings about using the following pattern? I had a very repetitive string generation code to write and was tempted to use this, but something about using locals() makes me uncomfortable. Is there any danger of unexpected behavior in this? Edit: context I found myself constantly writing stuff like: Answer There is now